📄 tanstack/router/latest/docs/framework/react/examples/basic-ssr-streaming-file-based

File: basic-ssr-streaming-file-based.md | Updated: 11/15/2025

Source: https://tanstack.com/router/latest/docs/framework/react/examples/basic-ssr-streaming-file-based



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

React logo

React

Version

Latest

Search...

+ K

Menu

Getting Started

Installation Guides

Routing

Guides

API

Integrations

ESLint

Router Examples

Framework

React logo

React

Version

Latest

Menu

Getting Started

Installation Guides

Routing

Guides

API

Integrations

ESLint

Router Examples

React Example: Basic Ssr Streaming File Based

Deploy to Cloudflare Deploy with Netlify Github StackBlitz

=================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

Code ExplorerCode

Interactive SandboxSandbox

  • .vscode

  • public

  • src

    • routes

      • posts

      • __root.tsx file icon__root.tsx

      • error.tsx file iconerror.tsx

      • index.tsx file iconindex.tsx

    • entry-client.tsx file iconentry-client.tsx

    • entry-server.tsx file iconentry-server.tsx

    • fetch-polyfill.js file iconfetch-polyfill.js

    • routeTree.gen.ts file iconrouteTree.gen.ts

    • router.tsx file iconrouter.tsx

    • routerContext.tsx file iconrouterContext.tsx

  • .gitignore file icon.gitignore

  • README.md file iconREADME.md

  • package.json file iconpackage.json

  • server.js file iconserver.js

  • tsconfig.json file icontsconfig.json

  • vite.config.ts file iconvite.config.ts

tsx

import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
import * as React from 'react'
import {
  HeadContent,
  Link,
  Outlet,
  Scripts,
  createRootRouteWithContext,
} from '@tanstack/react-router'
import type { RouterContext } from '../routerContext'

export const Route = createRootRouteWithContext<RouterContext>()({
  head: () => ({
    links: [{ rel: 'icon', href: '/images/favicon.ico' }],
    meta: [\
      {\
        title: 'TanStack Router SSR Basic File Based Streaming',\
      },\
      {\
        charSet: 'UTF-8',\
      },\
      {\
        name: 'viewport',\
        content: 'width=device-width, initial-scale=1.0',\
      },\
    ],
    scripts: [\
      {\
        src: 'https://unpkg.com/@tailwindcss/browser@4',\
      },\
      ...(!import.meta.env.PROD\
        ? [\
            {\
              type: 'module',\
              children: `import RefreshRuntime from "/@react-refresh"\
  RefreshRuntime.injectIntoGlobalHook(window)\
  window.$RefreshReg$ = () => {}\
  window.$RefreshSig$ = () => (type) => type\
  window.__vite_plugin_react_preamble_installed__ = true`,\
            },\
            {\
              type: 'module',\
              src: '/@vite/client',\
            },\
          ]\
        : []),\
      {\
        type: 'module',\
        src: import.meta.env.PROD\
          ? '/static/entry-client.js'\
          : '/src/entry-client.tsx',\
      },\
    ],
  }),
  component: RootComponent,
})

function RootComponent() {
  return (
    <html lang="en">
      <head>
        <HeadContent />
      </head>
      <body>
        <div className="p-2 flex gap-2 text-lg">
          <Link
            to="/"
            activeProps={{
              className: 'font-bold',
            }}
            activeOptions={{ exact: true }}
          >
            Home
          </Link>{' '}
          <Link
            to="/posts"
            activeProps={{
              className: 'font-bold',
            }}
          >
            Posts
          </Link>{' '}
          <Link
            to="/error"
            activeProps={{
              className: 'font-bold',
            }}
          >
            Error
          </Link>
        </div>
        <hr />
        <Outlet /> {/* Start rendering router matches */}
        <TanStackRouterDevtools position="bottom-right" />
        <Scripts />
      </body>
    </html>
  )
}


import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
import * as React from 'react'
import {
  HeadContent,
  Link,
  Outlet,
  Scripts,
  createRootRouteWithContext,
} from '@tanstack/react-router'
import type { RouterContext } from '../routerContext'

export const Route = createRootRouteWithContext<RouterContext>()({
  head: () => ({
    links: [{ rel: 'icon', href: '/images/favicon.ico' }],
    meta: [\
      {\
        title: 'TanStack Router SSR Basic File Based Streaming',\
      },\
      {\
        charSet: 'UTF-8',\
      },\
      {\
        name: 'viewport',\
        content: 'width=device-width, initial-scale=1.0',\
      },\
    ],
    scripts: [\
      {\
        src: 'https://unpkg.com/@tailwindcss/browser@4',\
      },\
      ...(!import.meta.env.PROD\
        ? [\
            {\
              type: 'module',\
              children: `import RefreshRuntime from "/@react-refresh"\
  RefreshRuntime.injectIntoGlobalHook(window)\
  window.$RefreshReg$ = () => {}\
  window.$RefreshSig$ = () => (type) => type\
  window.__vite_plugin_react_preamble_installed__ = true`,\
            },\
            {\
              type: 'module',\
              src: '/@vite/client',\
            },\
          ]\
        : []),\
      {\
        type: 'module',\
        src: import.meta.env.PROD\
          ? '/static/entry-client.js'\
          : '/src/entry-client.tsx',\
      },\
    ],
  }),
  component: RootComponent,
})

function RootComponent() {
  return (
    <html lang="en">
      <head>
        <HeadContent />
      </head>
      <body>
        <div className="p-2 flex gap-2 text-lg">
          <Link
            to="/"
            activeProps={{
              className: 'font-bold',
            }}
            activeOptions={{ exact: true }}
          >
            Home
          </Link>{' '}
          <Link
            to="/posts"
            activeProps={{
              className: 'font-bold',
            }}
          >
            Posts
          </Link>{' '}
          <Link
            to="/error"
            activeProps={{
              className: 'font-bold',
            }}
          >
            Error
          </Link>
        </div>
        <hr />
        <Outlet /> {/* Start rendering router matches */}
        <TanStackRouterDevtools position="bottom-right" />
        <Scripts />
      </body>
    </html>
  )
}

Basic + SSR (file-based)

Kitchen Sink (file-based)

Partners Become a Partner

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

scarf analytics