Skip to main content
This is the React InstantSearch v7 documentation. If you’re upgrading from v6, see the upgrade guide. If you were using React InstantSearch Hooks, this v7 documentation applies—just check for necessary changes. To continue using v6, you can find the archived documentation.
Synchronizing your UI with the browser URL is considered good practice. It lets your users take one of your results pages, copy the URL, and share it. It also improves the user experience by enabling the use of the back and next browser buttons to keep track of previous searches. InstantSearch provides the necessary API entries to let you synchronize the state of your search UI (your refined widgets and current ) with any kind of storage. Use the routing option to synchronize UI state with the browser URL, so users can bookmark, share, and revisit the same search. This guide covers enabling default routing, customizing URLs, and creating SEO-friendly URLs. If you’re using server-side rendering, follow the server-side rendering guide. If you’re using Next.js, see createInstantSearchRouterNext.
Don’t configure initialUiState and routing together.
  • Use initialUiState to set the UI state when the search first loads, such as for a default query or filter.
  • Use routing to keep the UI state synchronized with the URL, so users can bookmark or share a search.

Default URLs

Set routing to true to use the default routing configuration: a history router with simple state mapping. This stores routing-compatible UI state in URL query parameters.
React
Setting routing to true is equivalent to this configuration:
React
Assume the following search UI state:
  • Query: “galaxy”
  • Menu:
    • categories: “Cell Phones”
  • Refinement List:
    • brand: “Apple”, “Samsung”
  • Page: 2
This produces the following URL:
By default, routing includes state from routing-compatible widgets. With many widgets, this can create long URLs. To create shorter or more descriptive URLs, customize the URL routing.

Customize URL routing

You can customize which values appear and rename the URL parameters. The stateMapping option maps between InstantSearch’s uiState and the routeState used by the router. Use it to rename parameters or omit values that you don’t want to include in the URL.
React
InstantSearch stores widget state in uiState. The following example maps that state to shorter URL parameters. The state contains information about the user’s search, including the query, the selection, the page being viewed, and the widget hierarchy. uiState only stores modified widget values, not defaults. To persist this state in the URL, InstantSearch converts the uiState into an object called routeState: this routeState then becomes a URL. Conversely, when InstantSearch reads the URL and applies it to the search, it converts routeState into uiState. This logic lives in two functions:
  • stateToRoute: converts uiState to routeState.
  • routeToState: converts routeState to uiState.
Assume the following search UI state:
  • Query: “galaxy”
  • Menu:
    • categories: “Cell Phones”
  • Refinement List:
    • brand: “Apple” and “Samsung”
  • Page: 2
This translates into the following uiState:
JSON
Implement stateToRoute to flatten this object into a URL, and routeToState to restore the URL into a UI state:
React

SEO-friendly URLs

To create more descriptive URLs, move search state from query parameters into the URL path. This is a common pattern for ecommerce category and search pages.

Store categories in the URL path

This example stores the category in the path and the query, page, and brands as query parameters.
React
This example configures the default history router. The router reads and writes URLs, while stateMapping maps uiState to routeState and back. When you configure the history router, you can customize these functions:
  • windowTitle: returns the browser window title for a routeState.
  • createURL: creates a URL from routeState. InstantSearch calls it when synchronizing the browser URL, rendering links in the menu widget, or when a connector calls createURL.
  • parseURL: creates routeState from the URL when users load or reload the page or use the browser’s back or forward navigation.

Make URLs more discoverable

Shorter category URLs can be more readable and memorable. Use a mapping object to map category names to shorter URL slugs. Given the dataset in this guide, you can make some categories more discoverable:
  • “Cameras and camcorders” → /Cameras
  • “Car electronics and GPS” → /Cars
When users open https://example.org/search/Cameras, InstantSearch selects the “Cameras and camcorders” category. Define mappings between category names and URL slugs:
JavaScript
You can build these dictionaries from your Algolia . With such a solution, you have full control over what categories are discoverable from the URL.

About SEO

For your search results to be part of a public search engine’s results, you must be selective. Trying to index too many search results pages could be considered spam. To do that, create a robots.txt and host it at https://example.org/robots.txt. Here’s an example based on the URL scheme you created.
robots.txt

Basic routing demo

Explore basic InstantSearch routing in CodeSandbox.

SEO-friendly routing demo

Explore SEO-friendly routing in CodeSandbox.
Last modified on September 3, 2026