RouterProvider
Provide the router to components and manage browser lifecycle.
Compatibility
ReactAvailable in this renderer's browser integration.
React SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.
PreactAvailable in this renderer's browser integration.
Preact SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.
Import from @kasperrt/smolter/react @kasperrt/smolter/preact
Signature
function RouterProvider({
router,
children,
}: RouterProviderProps): ReactNode;Parameters
router is a stable instance from createRouter or createDataRouter. children contains the route renderer and shared layout. Data-specific hooks require createDataRouter.
Returns
A context provider element.
Usage
Import this API from one of the entry points listed above. Keep server and build helpers in their dedicated subpaths.
<RouterProvider router={router}>
<Header />
<Routes />
</RouterProvider>Behavior and edge cases
Do not recreate the router during render. Multiple providers can share a router: start reference-counts history listeners. Provider cleanup detaches its lifecycle subscription; use router.dispose when discarding the router itself.