A demonstration of how to implement dynamic breadcrumbs in TanStack Start that automatically update after mutations using router.invalidate().
š Live Demo ā | Deployed on Netlify with SSR support via Edge Functions
- Server-Side Rendering: Organizations and employees are loaded via server functions
- Dynamic Breadcrumbs: Breadcrumbs are prerendered on the server and update reactively on the client
- Real-time Updates: Edit organization/employee names and watch the breadcrumbs update instantly
- File-based Routing: Uses TanStack Router's file-based routing system
- Node.js 18+
- Bun (recommended) or npm
# Clone the repository git clone <repository-url> cd tanstack-start-router-breadcrumbs-example # Install dependencies bun install
# Start the dev server
bun devThe application will be available at http://localhost:3000
Each route defines a crumb property in its loader:
export const Route = createFileRoute('/organizations/$orgId')({ loader: async ({ params }) => { const organization = await getOrganization({ data: { id: params.orgId } }) return { crumb: organization.name, // Dynamic breadcrumb! organization, } }, })
The breadcrumb component uses useMatches() to reactively display all matched routes:
const BreadcrumbNav = () => { const matches = useMatches() const matchesWithCrumbs = matches.filter((match) => isMatch(match, 'loaderData.crumb'), ) // Renders breadcrumbs from loader data }
After mutations, call router.invalidate() to re-run loaders:
const handleUpdateName = async () => { await updateOrganization({ data: { id: orgId, name: newName } }) await router.invalidate() // This updates the breadcrumbs! }
- Home ā Landing page explaining the demo
- Breadcrumbs Demo ā Intro page
- Organizations ā List of organizations
- Organization Details ā View/edit organization name (watch breadcrumbs update!)
- Employees ā List of employees for the organization
- Employee Details ā View/edit employee name (watch breadcrumbs update!)
- TanStack Start: Full-stack React framework with server functions
- TanStack Router: Type-safe routing with file-based routing
- Server Functions: Run code on the server from client components
- SSR: Server-side rendering for fast initial page loads
- Tailwind CSS: Utility-first CSS framework
src/
āāā components/
ā āāā BreadcrumbNav.tsx # Breadcrumb navigation component
ā āāā Header.tsx # Application header
āāā data/
ā āāā organizations.ts # Server functions for CRUD operations
āāā routes/
ā āāā __root.tsx # Root layout with SSR setup
ā āāā index.tsx # Landing page
ā āāā demo/
ā āāā breadcrumbs/
ā āāā route.tsx # Layout with BreadcrumbNav
ā āāā index.tsx # Demo intro
ā āāā organizations/
ā āāā index.tsx # Organizations list
ā āāā $orgId/
ā āāā route.tsx # Organization loader
ā āāā index.tsx # Organization details
ā āāā employees/
ā āāā index.tsx # Employees list
ā āāā $employeeId.tsx # Employee details