pickstack

React + TanStack Router

Type-safe, file-based routing. This page shows exactly what pickstack adds to a React project for TanStack Router: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework react --modules tanstack-router --yes
Customize in the configurator

Packages it adds

PackageVersionType
@tanstack/react-router^1.170.46runtime
@tanstack/router-plugin^1.169.0dev

New files

src/routes/__root.tsx
import { createRootRoute, Link, Outlet } from "@tanstack/react-router";

export const Route = createRootRoute({
  component: RootLayout,
});

function RootLayout() {
  return (
    <main className="app">
      <nav className="nav">
        <Link className="link" to="/" activeOptions={{ exact: true }}>
          Home
        </Link>
        <Link className="link" to="/about">
          About
        </Link>
      </nav>
      <Outlet />
    </main>
  );
}
src/routes/about.tsx
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/about")({
  component: About,
});

function About() {
  return (
    <section className="page">
      <h1 className="title">About</h1>
      <p className="text">
        Built with React 19, Vite, TypeScript, TanStack Router.
      </p>
    </section>
  );
}
src/routes/index.tsx
import { createFileRoute } from "@tanstack/react-router";
import Counter from "../components/Counter";

export const Route = createFileRoute("/")({
  component: Home,
});

function Home() {
  return (
    <section className="page">
      <h1 className="title">my-app</h1>
      <Counter />
    </section>
  );
}
src/routeTree.gen.ts
/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file was automatically generated by TanStack Router.
// You should NOT make any changes in this file as it will be overwritten.
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.

import { Route as rootRouteImport } from './routes/__root'
import { Route as IndexRouteImport } from './routes/index'
import { Route as AboutRouteImport } from './routes/about'

const IndexRoute = IndexRouteImport.update({
  id: '/',
  path: '/',
  getParentRoute: () => rootRouteImport,
} as any)
const AboutRoute = AboutRouteImport.update({
  id: '/about',
  path: '/about',
  getParentRoute: () => rootRouteImport,
} as any)

export interface FileRoutesByFullPath {
  '/': typeof IndexRoute
  '/about': typeof AboutRoute
}
export interface FileRoutesByTo {
  '/': typeof IndexRoute
  '/about': typeof AboutRoute
}
export interface FileRoutesById {
  __root__: typeof rootRouteImport
  '/': typeof IndexRoute
  '/about': typeof AboutRoute
}
export interface FileRouteTypes {
  fileRoutesByFullPath: FileRoutesByFullPath
  fullPaths: '/' | '/about'
  fileRoutesByTo: FileRoutesByTo
  to: '/' | '/about'
  id: '__root__' | '/' | '/about'
  fileRoutesById: FileRoutesById
}
export interface RootRouteChildren {
  IndexRoute: typeof IndexRoute
  AboutRoute: typeof AboutRoute
}

declare module '@tanstack/react-router' {
  interface FileRoutesByPath {
    '/': {
      id: '/'
      path: '/'
      fullPath: '/'
      preLoaderRoute: typeof IndexRouteImport
      parentRoute: typeof rootRouteImport
    }
    '/about': {
      id: '/about'
      path: '/about'
      fullPath: '/about'
      preLoaderRoute: typeof AboutRouteImport
      parentRoute: typeof rootRouteImport
    }
  }
}

const rootRouteChildren: RootRouteChildren = {
  IndexRoute: IndexRoute,
  AboutRoute: AboutRoute,
}
export const routeTree = rootRouteImport
  ._addFileChildren(rootRouteChildren)
  ._addFileTypes<FileRouteTypes>()

Changes to existing files

src/main.tsx (changed)
+import { createRouter, RouterProvider } from "@tanstack/react-router"; import { StrictMode } from "react"; import { createRoot } from "react-dom/client";+import { routeTree } from "./routeTree.gen";−import App from "./App"; import "./index.css";  +const router = createRouter({ routeTree });+ +declare module "@tanstack/react-router" {+  interface Register {+    router: typeof router;+  }+}+  createRoot(document.getElementById("root")!).render(   <StrictMode>+    <RouterProvider router={router} />−    <App />   </StrictMode>, );  
vite.config.ts (changed)
+import { tanstackRouter } from "@tanstack/router-plugin/vite"; import react from "@vitejs/plugin-react"; import { defineConfig } from "vite";   export default defineConfig({+  plugins: [+    tanstackRouter({ target: "react", autoCodeSplitting: true }),+    react(),+  ],−  plugins: [react()], });  

Project files

Related templates