📄 tanstack/router/latest/docs/framework/solid/guide/static-route-data

File: static-route-data.md | Updated: 11/15/2025

Source: https://tanstack.com/router/latest/docs/framework/solid/guide/static-route-data



TanStack

Router v1v1

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

Solid logo

Solid

Version

Latest

Search...

+ K

Menu

Getting Started

Installation Guides

Routing

Guides

API

ESLint

Router Examples

Framework

Solid logo

Solid

Version

Latest

Menu

Getting Started

Installation Guides

Routing

Guides

API

ESLint

Router Examples

On this page

Static Route Data

Copy Markdown

When creating routes, you can optionally specify a staticData property in the route's options. This object can literally contain anything you want as long as it's synchronously available when you create your route.

In addition to being able to access this data from the route itself, you can also access it from any match under the match.staticData property.

Example
-------

  • posts.tsx

tsx

import { createFileRoute } from '@tanstack/solid-router'

export const Route = createFileRoute('/posts')({
  staticData: {
    customData: 'Hello!',
  },
})


import { createFileRoute } from '@tanstack/solid-router'

export const Route = createFileRoute('/posts')({
  staticData: {
    customData: 'Hello!',
  },
})

You can then access this data anywhere you have access to your routes, including matches that can be mapped back to their routes.

  • __root.tsx

tsx

import { createRootRoute } from '@tanstack/solid-router'

export const Route = createRootRoute({
  component: () => {
    const matches = useMatches()

    return (
      <div>
        {matches.map((match) => {
          return <div key={match.id}>{match.staticData.customData}</div>
        })}
      </div>
    )
  },
})


import { createRootRoute } from '@tanstack/solid-router'

export const Route = createRootRoute({
  component: () => {
    const matches = useMatches()

    return (
      <div>
        {matches.map((match) => {
          return <div key={match.id}>{match.staticData.customData}</div>
        })}
      </div>
    )
  },
})

Enforcing Static Data
---------------------

If you want to enforce that a route has static data, you can use declaration merging to add a type to the route's static option:

tsx

declare module '@tanstack/solid-router' {
  interface StaticDataRouteOption {
    customData: string
  }
}


declare module '@tanstack/solid-router' {
  interface StaticDataRouteOption {
    customData: string
  }
}

Now, if you try to create a route without the customData property, you'll get a type error:

tsx

import { createFileRoute } from '@tanstack/solid-router'

export const Route = createFileRoute('/posts')({
  staticData: {
    // Property 'customData' is missing in type '{ customData: number; }' but required in type 'StaticDataRouteOption'.ts(2741)
  },
})


import { createFileRoute } from '@tanstack/solid-router'

export const Route = createFileRoute('/posts')({
  staticData: {
    // Property 'customData' is missing in type '{ customData: number; }' but required in type 'StaticDataRouteOption'.ts(2741)
  },
})

Optional Static Data
--------------------

If you want to make static data optional, simply add a ? to the property:

tsx

declare module '@tanstack/solid-router' {
  interface StaticDataRouteOption {
    customData?: string
  }
}


declare module '@tanstack/solid-router' {
  interface StaticDataRouteOption {
    customData?: string
  }
}

As long as there are any required properties on the StaticDataRouteOption, you'll be required to pass in an object.

Edit on GitHub

Scroll Restoration

SSR

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics