Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useRoute() React hook #473

Merged
merged 5 commits into from
Sep 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add useRoute hook
  • Loading branch information
bakerkretzmar committed Sep 1, 2023
commit f189c7b460080b2ac6e7113694c720a032277c00
9 changes: 9 additions & 0 deletions src/js/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import route from './index.js';

export const useRoute = (defaultConfig) => {
if (!defaultConfig && !globalThis.Ziggy && typeof Ziggy === 'undefined') {
throw new Error('Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into the useRoute hook.');
}

return (name, params, absolute, config = defaultConfig) => route(name, params, absolute, config);
};