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.
Signature
Import
JavaScript
About this function
createInstantSearchNextRouter
is a function that creates a Next.js-compatible InstantSearch router to pass to <InstantSearch>
routing
prop.
It fixes some issues with the default router,
such as the page not updating when using the browser’s back and forward buttons,
or when navigating from a Next.js <Link>
containing an InstantSearch query.
It’s based on history
so you can easily migrate from it by passing the same options to routerOptions
.
Requirements
This function is available from the companionreact-instantsearch-router-nextjs
package.
You can’t use this function with
getStaticProps
.
Use getServerSideProps
or client-side rendering instead.Examples
Parameters
The Next.js singleton router instance to use.
It is the default export of
next/router
.JavaScript
The URL of the page on the server.
It is used by the router to determine the initial state of the search.
Required only when using SSR.
JavaScript
A function called before the router starts.
You can use it to inform InstantSearch to update on router events by calling onUpdate.
It is here for troubleshooting purposes or if you’re using a custom router with Next.js.
JavaScript
A function called before the router gets disposed of.
You can use it to detach event handlers you may have set up in
beforeStart
.
It is here for troubleshooting purposes or if you’re using a custom router with Next.js.JavaScript
A function used by the Next.js router to know whether it should trigger SSR when using back/forward buttons. You can use it to override the default one by writing your own logic. The
ownBeforePopState
is the pre-existing handler that you may have set yourself, and the libraryBeforePopState
is the default one from the library.
It is here for troubleshooting purposes, you should not need to use it.Options contains the following properties:state: NextHistoryState
. The next state to apply.ownBeforeState: BeforePopStateCallback
. Either the default handler which just returnstrue
, or the one you set yourself.libraryBeforeState: BeforePopStateCallback
. The default handler of the library which returnstrue
if going on a different page, orfalse
if staying on the same page.
JavaScript
You can pass options to the underlying history router.
These will override the ones created by
createInstantSearchRouterNext
.You can check history
for more information about the options.JavaScript