Custom Location Hooks
wouter-vue supports custom location hooks for different routing behaviors.
Hash-based Routing
Use hash-based routing (e.g., #/about) instead of browser history:
Example URLs:
http://example.com/#/abouthttp://example.com/#/users/123
Memory Location (Testing)
Use memory location for testing - routes don’t affect browser history:
Use cases:
- Unit testing
- Component testing
- Storybook stories
- Isolated routing scenarios
Creating Custom Hooks
You can create custom location hooks by implementing the LocationHook interface:
Example:
Notes
- Default location hook is
useBrowserLocation()(browser history API) - Hash location is useful for static hosting without server configuration
- Memory location is perfect for testing environments
- Important: Router component uses
:hookprop, not:location - Custom hooks must be functions that accept a
RouterObjectand return[Ref<Path>, NavigateFn] - For
memoryLocation, callhook()once and reuse the result to ensure all components share the same reactive state