Overview
URL routing provides:- Shareable searches - Users can share search URLs
- Browser navigation - Back/forward buttons work correctly
- Bookmarkable results - Save specific search states
- SEO benefits - Search engines can index filtered states
- Deep linking - Link directly to specific search configurations

Basic Implementation
JavaScript
Enable routing with a single option:React
Advanced Routing Configuration
Custom State Mapping
Control how search state maps to URLs:- JavaScript
- State Mapping
- Complete Setup
URL Formats
Query String Format (Default)
Simple format with query parameters:SEO-Friendly URLs
Clean URLs with path segments:Hash-Based Routing
For static hosting or SPAs:React with Next.js Routing
Next.js Pages Router
Prefilled Queries
Create links with predefined search states:Custom URL Schemes
Clean Category URLs
Encode category names for cleaner URLs:Omit Default Values
Keep URLs clean by excluding default values:Window Title Updates
Update the browser tab title based on search state:Routing Options
Clean URL on Unmount
Reset URL when search is unmounted:Debounce URL Updates
Reduce URL updates during typing:Custom Query String Format
State Persistence
Routing automatically persists state in the URL. For additional persistence:Session Storage
Testing Routing
Verify URL Updates
- Open your search interface
- Type a query - URL should update
- Select filters - URL should include refinements
- Click pagination - URL should show page number
- Copy URL, open in new tab - state should be preserved
Check Browser Navigation
- Perform several searches
- Click browser back button - should restore previous search
- Click browser forward button - should restore next search
Common Issues
Double Encoding
Avoid double-encoding URLs:Missing State After Refresh
Ensure yourparseURL correctly reads all parameters:
Running the Example
- JavaScript
- React
- Next.js
Customization Tips
Create shareable search links
Create shareable search links
Implement search presets
Implement search presets
Create predefined search configurations as clickable links or buttons.
Add analytics tracking
Add analytics tracking
Track URL changes to measure popular search configurations.
Validate URL parameters
Validate URL parameters
Add validation in
parseURL to handle malformed or invalid URLs gracefully.Related Examples
- E-Commerce Search - See routing in a complete e-commerce context
- Next.js SSR - Server-side rendering with routing
- Multi-Index Search - Routing with multiple indices
Source Code
JavaScript
View routing implementation
React
View routing implementation
Next.js
View Next.js routing example