📄 tanstack/router/latest/docs/framework/solid/examples/router-monorepo-simple-lazy

File: router-monorepo-simple-lazy.md | Updated: 11/15/2025

Source: https://tanstack.com/router/latest/docs/framework/solid/examples/router-monorepo-simple-lazy



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

Solid Example: Router Monorepo Simple Lazy

Deploy to Cloudflare Deploy with Netlify Github StackBlitz

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

Code ExplorerCode

Interactive SandboxSandbox

  • .vscode

  • assets

  • packages

    • app

      • src

        • main.tsx file iconmain.tsx

        • rootComponent.tsx file iconrootComponent.tsx

        • style.css file iconstyle.css

      • index.html file iconindex.html

      • package.json file iconpackage.json

      • tsconfig.json file icontsconfig.json

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

    • post-feature

    • router

  • .gitignore file icon.gitignore

  • .stackblitzrc file icon.stackblitzrc

  • README.md file iconREADME.md

  • package.json file iconpackage.json

  • pnpm-workspace.yaml.example file iconpnpm-workspace.yaml.example

tsx

import { render } from 'solid-js/web'
import { RouterProvider } from '@tanstack/solid-router'
import { router } from '@router-solid-mono-simple-lazy/router'
import { RootComponent } from './rootComponent'
import type {
  RouteById,
  RouterIds,
} from '@router-solid-mono-simple-lazy/router'
import type { LazyRoute } from '@tanstack/solid-router'
import './style.css'

// Generic to enforce that the route returned matches the route path
type LazyRouteFn<TRoutePath extends RouterIds> = () => Promise<
  LazyRoute<RouteById<(typeof router)['routeTree'], TRoutePath>>
>

type RouterMap = {
  // __root__ is a special route that isn't lazy loaded, so we need to manually bind it
  // You could consider adding null to the returned type to have routes without rendering
  [K in Exclude<RouterIds, '__root__'>]: LazyRouteFn<K>
}

const routerMap: RouterMap = {
  '/': () =>
    import('@router-solid-mono-simple-lazy/post-feature/post-list').then(
      (d) => d.PostRoute,
    ),
  '/$postId': () =>
    import('@router-solid-mono-simple-lazy/post-feature/post-id-page').then(
      (d) => d.PostIdRoute,
    ),
}

// Given __root__ is a special route that isn't lazy loaded, we need to update it manually
router.routesById['__root__'].update({
  component: RootComponent,
})

Object.entries(routerMap).forEach(([path, component]) => {
  const foundRoute = router.routesById[path as RouterIds]
  // Bind the lazy route to the actual route
  foundRoute.lazy(component)
})

// Render the app
const rootElement = document.getElementById('app')!

if (!rootElement.innerHTML) {
  render(() => <RouterProvider router={router} />, rootElement)
}


import { render } from 'solid-js/web'
import { RouterProvider } from '@tanstack/solid-router'
import { router } from '@router-solid-mono-simple-lazy/router'
import { RootComponent } from './rootComponent'
import type {
  RouteById,
  RouterIds,
} from '@router-solid-mono-simple-lazy/router'
import type { LazyRoute } from '@tanstack/solid-router'
import './style.css'

// Generic to enforce that the route returned matches the route path
type LazyRouteFn<TRoutePath extends RouterIds> = () => Promise<
  LazyRoute<RouteById<(typeof router)['routeTree'], TRoutePath>>
>

type RouterMap = {
  // __root__ is a special route that isn't lazy loaded, so we need to manually bind it
  // You could consider adding null to the returned type to have routes without rendering
  [K in Exclude<RouterIds, '__root__'>]: LazyRouteFn<K>
}

const routerMap: RouterMap = {
  '/': () =>
    import('@router-solid-mono-simple-lazy/post-feature/post-list').then(
      (d) => d.PostRoute,
    ),
  '/$postId': () =>
    import('@router-solid-mono-simple-lazy/post-feature/post-id-page').then(
      (d) => d.PostIdRoute,
    ),
}

// Given __root__ is a special route that isn't lazy loaded, we need to update it manually
router.routesById['__root__'].update({
  component: RootComponent,
})

Object.entries(routerMap).forEach(([path, component]) => {
  const foundRoute = router.routesById[path as RouterIds]
  // Bind the lazy route to the actual route
  foundRoute.lazy(component)
})

// Render the app
const rootElement = document.getElementById('app')!

if (!rootElement.innerHTML) {
  render(() => <RouterProvider router={router} />, rootElement)
}

Monorepo basic

Monorepo with Solid Query

Partners Become a Partner

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

scarf analytics