react-instantsearch-router-nextjs
Version:
React InstantSearch Router for Next.js
60 lines (59 loc) • 2.42 kB
TypeScript
import type { Router, UiState } from 'instantsearch.js';
import type { BrowserHistoryArgs } from 'instantsearch.js/es/lib/routers/history';
import type { Router as NextRouter, SingletonRouter } from 'next/router';
type BeforePopStateCallback = NonNullable<NextRouter['_bps']>;
type NextHistoryState = Parameters<BeforePopStateCallback>[0];
type CreateInstantSearchRouterNextOptions<TRouteState> = {
/**
* The Next.js singleton router instance.
*
* @example
* import singletonRouter from 'next/router';
* import { createInstantSearchNextRouter } from 'react-instantsearch-router-nextjs';
*
* const router = createInstantSearchNextRouter({ singletonRouter });
*/
singletonRouter: SingletonRouter;
/**
* Required URL when rendering on the server.
*/
serverUrl?: string;
/**
* If you need to add additional logic to the `beforePopState` method of the Next.js router,
* you can use this option.
**/
beforePopState?: (options: {
/**
* The Next.js router's `beforePopState` method.
*/
state: NextHistoryState;
/**
* The library's default `beforePopState` method.
* It returns `false` if staying on the same page to avoid unnecessary SSR.
*/
libraryBeforePopState: BeforePopStateCallback;
/**
* Your own `beforePopState` method if you had set one before.
* You can use it to compose your own logic for whether to call SSR or not.
*/
ownBeforePopState: BeforePopStateCallback;
}) => boolean;
/**
* Called before the router starts.
* Useful to add additional logic if you need the router to tell InstantSearch when to update.
*/
beforeStart?: BrowserHistoryArgs<TRouteState>['start'];
/**
* Called before the router disposes.
* Useful to detach what was attached in `beforeStart`.
*/
beforeDispose?: () => void;
/**
* Options passed to the underlying history router.
* See https://www.algolia.com/doc/api-reference/widgets/history-router/react/
* for the list of available options.
*/
routerOptions?: Partial<Omit<BrowserHistoryArgs<TRouteState>, 'start' | 'dispose'>>;
};
export declare function createInstantSearchRouterNext<TRouteState = UiState>(options: CreateInstantSearchRouterNextOptions<TRouteState>): Router<TRouteState>;
export {};