Overview
The URL module synchronizes your search interface state with the browser’s URL, enabling:- State persistence across page reloads
- Browser history navigation (back/forward buttons)
- Shareable search URLs
- SEO-friendly URLs
When to Use
Use URL state management when you need to:- Preserve search state when users refresh the page
- Support browser back/forward navigation
- Enable sharing of search results via URL
- Track search parameters for analytics
- Build SEO-friendly search pages
Configuration and Setup
Basic Usage
Add theUrlHandler component to your application. This component manages URL synchronization automatically:
Custom URL Parameter Names
You can customize the URL parameter names by passing props to theUrlHandler component:
query→qpage→pfilter→fsort→s
?q=shoes&p=2&f=brand:nike&s=price:asc
Managing Extra Parameters
You can include custom parameters in the URL by adding them as props:API Reference
UrlHandler Component
The main component for URL state management. Props:- Any attribute you pass will be used as a URL parameter mapping
- The prop name is the internal parameter name
- The prop value (if string) is the URL parameter name
ParamsLoadedFromUrl- Emitted when URL parameters are loaded on page loadExtraParamsLoadedFromUrl- Emitted when extra parameters are detected in the URLUserOpenXProgrammatically- Emitted when a query is detected in the URL on page load
Store State
Store Getters
Store Mutations
Events
Examples
Read URL Parameters on Load
The URL module automatically reads parameters when the page loads. Listen to theParamsLoadedFromUrl event:
Programmatically Update URL
You can update URL parameters by dispatching events or committing mutations:Building SEO-Friendly URLs
The URL module automatically:- Sorts parameters alphabetically for consistent URLs
- Properly encodes special characters
- Only includes parameters when a query is present
- Normalizes spaces to
%20instead of+
?f=brand:nike&f=color:blue&q=running+shoes becomes ?f=brand:nike&f=color:blue&q=running%20shoes
History Management
The module uses two different events for history management:PushableUrlStateUpdated- Creates a new history entry (push)ReplaceableUrlStateUpdated- Replaces current history entry (replace)
PushableUrlStateUpdated to allow back/forward navigation.
Handling Browser Navigation
TheUrlHandler listens to browser popstate events automatically:
- The
popstateevent is captured - URL parameters are parsed
ParamsLoadedFromUrlevent is emitted- Your search interface updates accordingly
Advanced Usage
SPA Mode
For single-page applications, the URL module detects SPA navigation:Back-Forward Cache Detection
The module handles browser back-forward cache (bfcache):Custom Wiring
You can wire custom events to URL mutations:Best Practices
- Use short parameter names for cleaner URLs:
qinstead ofquery,pinstead ofpage - Only store essential state in the URL - don’t include UI-specific state
- Validate URL parameters on load to handle malformed or invalid values
- Consider SEO impact - search engines will index your URL parameters
- Test browser navigation - ensure back/forward buttons work correctly
- Handle missing parameters - provide defaults when parameters are absent
