history
This is the React InstantSearch v7 documentation. React InstantSearch v7 is the latest version of React InstantSearch and the stable version of React InstantSearch Hooks.
If you were using React InstantSearch v6, you can upgrade to v7.
If you were using React InstantSearch Hooks, you can still use the React InstantSearch v7 documentation, but you should check the upgrade guide for necessary changes.
If you want to keep using React InstantSearch v6, you can find the archived documentation.
const router = history({ // Optional parameters windowTitle: function, createURL: function, parseURL: function, writeDelay: number, getLocation: function, push: function, start: function, dispose: function, cleanUrlOnDispose: boolean, })
1
import { history } from 'instantsearch.js/es/lib/routers';
About this function
The history
router is the default for the <InstantSearch>
component’s routing prop.
The router provides an API that lets you customize some of its behaviors. To get a sense of what you can do with the API, see the Routing URLs guide.
Consider using createInstantSearchRouterNext()
in a Next.js environment to better leverage its routing capabilities.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { InstantSearch } from 'react-instantsearch';
import { history } from 'instantsearch.js/es/lib/routers';
const routing = {
router: history(),
};
function App() {
return (
<InstantSearch
searchClient={searchClient}
indexName="instant_search"
routing={routing}
>
{/* ... */}
</InstantSearch>
);
}
Options
windowTitle
|
type: function
Optional
This function lets you dynamically customize the window title based on the provided |
||
Copy
|
|||
createURL
|
type: function
Optional
This function lets you directly change the format of URLs that are created and rendered for the browser URL bar or widgets. It’s called every time InstantSearch needs to create a URL. The provided options are:
|
||
Copy
|
|||
parseURL
|
type: function
Optional
This function is responsible for parsing the URL string back into a
|
||
Copy
|
|||
writeDelay
|
type: number
default: 400
Optional
This option controls the number of milliseconds the router waits before writing the new URL to the browser. You can think about it this way: “400 ms after the last user action, the URL is pushed to the browser”. This helps reduce:
400 ms is a typically a pretty good |
||
Copy
|
|||
getLocation
|
type: function
default: () => window.location
Optional
This function lets you return a custom implementation of By default, it generates an error if there isn’t a custom implementation outside a browser environment. |
||
Copy
|
|||
push
|
type: function
Optional
This function lets you customize the behavior of the router when it pushes a new URL so that you can delegate it to a third party router or set a custom history state. It’s called every time users refine the UI and the history timer completes. The provided option is:
|
||
Copy
|
|||
start
|
type: function
Optional
This function is called when the router starts. You can use it to synchronize InstantSearch’s router with a third party router by hooking events to it. The provided option is:
|
||
Copy
|
|||
dispose
|
type: function
Optional
This function is called when the router gets disposed of. You can use it to detach events you may have set in |
||
Copy
|
|||
cleanUrlOnDispose
|
since: v7.5.0
type: boolean
default: true
Optional
This option controls whether the URL is cleaned up from active refinements when the router is disposed of. It’s useful when the search experience is in a modal, to remove query parameters from the URL when the modal is closed. |
||
Copy
|