pickstack

SolidJS + TanStack Router

Type-safe, file-based routing. This page shows exactly what pickstack adds to a SolidJS 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 solid --modules tanstack-router --yes
Customize in the configurator

Packages it adds

PackageVersionType
@tanstack/solid-router^1.170.43runtime
@tanstack/router-plugin^1.169.0dev

New files

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

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

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

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

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

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

function Home() {
  return (
    <section class="page">
      <h1 class="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/solid-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/index.tsx (changed)
 /* @refresh reload */+import { createRouter, RouterProvider } from "@tanstack/solid-router"; import { render } from "solid-js/web";+import { routeTree } from "./routeTree.gen";−import App from "./App"; import "./index.css";  +const router = createRouter({ routeTree });+ +declare module "@tanstack/solid-router" {+  interface Register {+    router: typeof router;+  }+}+  const root = document.getElementById("root");  +render(() => <RouterProvider router={router} />, root!);−render(() => <App />, root!);  
vite.config.ts (changed)
+import { tanstackRouter } from "@tanstack/router-plugin/vite"; import { defineConfig } from "vite"; import solid from "vite-plugin-solid";   export default defineConfig({+  plugins: [+    tanstackRouter({ target: "solid", autoCodeSplitting: true }),+    solid(),+  ],−  plugins: [solid()], });  

Project files

Related templates