FUNSTACK Router

HomeGetting StartedLearnAPI ReferenceExamplesFAQ
GitHub

Built with @funstack/router — A modern React router based on the Navigation API

Getting Started

  • Getting Started
  • Examples

Learn

  • Overview
  • Navigation API
  • Nested Routes
  • Type Safety
  • Form Actions
  • How Loaders Run
  • Error Handling
  • Transitions
  • SSR
    • How SSR Works
    • Static Site Generation
    • SSR with Loaders
  • RSC
    • React Server Components
    • RSC with Route Features

API Reference

  • Overview
  • Components
  • Hooks
  • Utilities
  • Types

Resources

  • FAQ
  • GitHub ↗

API Reference

ComponentsHooksUtilitiesTypes

Components

Core components for building routing in your React application.

<Router>

The main router component that provides routing context.

import { Router } from "@funstack/router";

<Router
  routes={routes}
  onNavigate={(event, info) => {
    console.log("Navigating to:", event.destination.url);
    console.log("Matched routes:", info.matches);
    console.log("Will intercept:", info.intercepting);
  }}
/>

Props

PropTypeDescription
routesRouteDefinition[]Array of route definitions
onNavigateOnNavigateCallbackCallback fired before navigation is intercepted. Receives the NavigateEvent and an info object with matched routes and whether the router will intercept the navigation.
fallback"none" | "static"Fallback mode when Navigation API is unavailable. "none" (default) renders nothing; "static" renders matched routes using window.location without navigation interception (MPA behavior).
trailingSlash"ignore" | "strict"How trailing slashes are treated during route matching. "ignore" (default) ignores a single trailing slash on the pathname or on route path patterns, so /users/ matches path: "/users"; the URL itself is never rewritten. "strict" requires pathnames to match patterns exactly.
ssrSSRConfigSSR configuration for route matching during server-side rendering. Accepts an object with path (the pathname to match against) and an optional runLoaders boolean (defaults to false). When runLoaders is false, routes with loaders are skipped during SSR. Once the client hydrates, the real URL from the Navigation API takes over. See the SSR guide for details.
transitionTypesGetTransitionTypesFunction returning the React transition types to attach to each navigation via addTransitionType (React 19.3+). Receives the destination url and navigationType; the returned types replace the default ["navigation"]. See the Transitions guide for details.
featuresRouterFeaturesOpt-in feature flags that change the Router's behavior. Currently supports pathlessSSROutletDeferral, which uses React's browser() API (React 19.3+) to defer unmatched outlet content to the browser during pathless SSR (this will become the default behavior in the next major version). See the SSR guide for details.

<RouteDisplay>

Renders the routes matching the current URL, without client-side routing. Unlike <Router>, it does not intercept navigations: links and form submissions cause regular full page loads. Use it for multi-page applications (MPAs) where each page is a separate document but still uses route definitions to decide what to render. It works in all browsers, with or without the Navigation API.

import { RouteDisplay } from "@funstack/router";

// Client: matches routes against the current page URL
<RouteDisplay routes={routes} />

// Server: matches routes against the given path
<RouteDisplay routes={routes} ssr={{ path: "/about", runLoaders: true }} />

Hooks that read the location (useLocation, useSearchParams, useRouteParams, useRouteData, etc.) work as usual. It follows the current location the same way as <Router>: when the Navigation API is available, the current entry's id, key and state are exposed (so route state works too), and same-document entry changes such as fragment navigations are rendered in a transition. Without the Navigation API, these values are null / undefined.

Setters that navigate (such as the one from useSearchParams, or a route's setState) perform a full page navigation. With the Navigation API, the new entry keeps the given state; without it, the state is lost. setStateSync updates the current entry's state in place without navigating (Navigation API only). Features that depend on intercepting navigations are inert: useBlocker never blocks, and route actions are not run (forms submit to the server).

<RouteDisplay> assumes that nothing else on the page intercepts navigations. If another library intercepts them with the Navigation API, entry changes are still rendered, but behaviors that depend on <Router>'s own interception are missing: for example, loaders do not re-run on an intercepted reload, and the navigation info is not exposed.

Props

PropTypeDescription
routesRouteDefinition[]Array of route definitions
ssrSSRConfigSame as <Router>'s ssr prop. Used only during SSR and hydration; afterwards, the page URL from window.location takes over.
trailingSlash"ignore" | "strict"Same as <Router>'s trailingSlash prop.
featuresRouterFeaturesSame as <Router>'s features prop.

<Outlet>

Renders the child route's component. Used in parent routes for nested layouts.

import { Outlet } from "@funstack/router";

function Layout() {
  return (
    <div>
      <header>My App</header>
      <main>
        <Outlet />
      </main>
    </div>
  );
}