Skip to main content

Solid Router

TanStack Router provides first-class support for SolidJS with reactive primitives, components, and patterns designed specifically for Solid applications.

Installation

Core Components

RouterProvider

The top-level component that renders active route matches and provides the router to the Solid tree via context.
Reactive navigation component with preloading and active state support.
Note: Use class instead of className (Solid convention). Key Props:
  • to - Type-safe destination path
  • params - Path parameters
  • search - Search parameters
  • activeProps - Props applied when link is active (returns a function in Solid)
  • inactiveProps - Props applied when link is inactive
  • preload - Controls preloading behavior (false, 'intent', 'viewport')
  • disabled - Disables navigation

Outlet

Renders child route matches at the current level.

ErrorComponent

Default error boundary component that displays error details.
Component-based navigation trigger.

Solid Primitives

useRouter

Access the router instance from any component.

useNavigate

Type-safe programmatic navigation.

useParams

Access route path parameters reactively.
Note: In Solid, useParams returns a reactive proxy, not a signal.

useSearch

Access route search parameters reactively.

useLoaderData

Access data loaded by the route’s loader function as a signal.
Key Difference: In Solid, useLoaderData returns a signal (function), so access data with post() instead of post.

useMatch

Access the current route match with reactive properties.

useRouteContext

Access route context provided by parent routes reactively.

useLocation

Access the current location object reactively.

useRouterState

Access router state reactively with optional selector.
Note: Returns a signal, so access with isLoading().

useMatchRoute

Check if a specific route matches the current location.

useLinkProps

Build anchor-like props for custom link components.

useBlocker

Block navigation based on a condition (useful for unsaved changes).

Route API

RouteApi

Route-specific API with pre-bound reactive primitives for a specific route ID.

Creating Routes

Code-based Routes

File-based Routes

SSR Support

Solid Router includes specialized SSR utilities:

Solid-Specific Features

Reactive Data Flow

All router state is fully reactive and integrates with Solid’s reactivity system:

Signal-based Loader Data

Loader data is returned as Solid signals:

Suspense Integration

Works seamlessly with Solid’s Suspense:

Show/Match Components

Use Solid’s control flow components:

Complete Example

Best Practices

  1. Type Safety: Always register your router type:
  2. Use Signals: Remember that useLoaderData and useRouterState return signals:
  3. Reactive Params: useParams and useSearch return reactive proxies:
  4. Control Flow: Use Solid’s control flow components:
  5. Class vs ClassName: Use class (Solid convention) instead of className:

Key Differences from React Router

  • Signals: useLoaderData and useRouterState return signals, not plain values
  • Reactive Proxies: useParams and useSearch return reactive proxies
  • Class Attribute: Use class instead of className
  • Control Flow: Use Show, For, Switch, Match instead of &&, map, ternaries
  • No Hooks Rules: Solid doesn’t have hook rules - use primitives anywhere