Before we dive into the details of the projects, please take a moment to support the project and the community:
- π₯ Subscribe to the tapaScript YouTube Channel for structured programming tutorials, web development deep-dives, and frontend/backend courses.
- βοΈ Star this Repository on GitHub to show your appreciation and help other developers find it!
- π Support & Sponsor the creator on GitHub Sponsors to keep open-source education free and sustainable.
This repository is a comprehensive, hands-on learning environment for mastering TanStack Router in React. It contains a full-stack structure split into two separate directories:
meetup-mock-api: A mock backend REST API built usingjson-serverto serve event database entries.meetup-tracker: A modern React 19 application showcasing core and advanced patterns of TanStack Router.
tanstack-router-crash-course/
βββ meetup-mock-api/ # Mock REST API backend
β βββ db.json # JSON database file
β βββ package.json # Server configuration
βββ meetup-tracker/ # React 19 frontend app
βββ src/
β βββ components/ # Shared UI components
β βββ routes/ # File-based routes & components
β βββ utils/ # Authentication & helpers
β βββ main.tsx # App entrypoint & context injection
β βββ router.tsx # Router setup & TS register declarations
βββ package.json # Dependencies & scripts
βββ tsr.config.json # TanStack Router configurationThe meetup-mock-api project provides a lightweight, local mock REST API server that feeds event and meetup details to the React frontend application.
- json-server: A tool to create a full mock REST API with zero coding.
- Node.js & npm/pnpm: Package management.
The database contains a list of events/meetups under the events collection. Each meetup object has the following schema:
id(string): Unique identifier (e.g.,"react-kolkata").title(string): The title/name of the meetup.date(string): Date inYYYY-MM-DDformat.location(string): The venue or area hosting the event.description(string): Detailed explanation of the event scope.attendees(number): Number of RSVP'd attendees.city(string): The host city (e.g.,"Kolkata","Bengaluru").tech(string): Primary technology stack (e.g.,"React","Full-Stack").
To launch the mock server on port 3001:
cd meetup-mock-api
pnpm install
pnpm start- Endpoint URL: http://localhost:3001/events
The meetup-tracker project is a fully-featured frontend application showcasing the best routing mechanism available for the web today: TanStack Router. It contains practical examples ranging from simple routing to advanced concepts.
- React 19 & TypeScript
- Vite: Frontend build system.
- Tailwind CSS v4: Utility-first styles.
- TanStack Router & TanStack Devtools: Fully type-safe file-based router.
- Zod: Schema declaration and validation.
- Vitest: Modern testing framework.
-
Shows how to construct the router instance using
createRouterand export it type-safely. -
Demonstrates how to inject dependencies (like the
authhelper object) globally into the routing context. -
Declares the global typescript module expansion to register the router interface:
declare module '@tanstack/react-router' { interface Register { router: typeof router } }
- Uses
createRootRouteWithContextto define a global wrapper context. - Provides the shared markup, header navigation, and the
<Outlet />element where active route pages are rendered. - Integrates the
<TanStackDevtools />and<TanStackRouterDevtoolsPanel />plugins directly into the UI.
- Includes typical static routes like Home (
/) and About (/about). - Demonstrates declarative navigation with
<Link>components. - Demonstrates programmatic navigation via the
useNavigatehook, triggering an automatic redirect when a counter button is clicked 3 times.
- Uses dynamic route parameters (
$meetupId). - The route
loadergrabsparams.meetupIdto request the corresponding event detail page from the mock server. - Specifies a custom
pendingComponentto render skeleton states during fetching and anerrorComponentto capture route failures.
- Demonstrates how parent layouts wrap nested paths (e.g.
index.tsx,create.tsx,$meetupId.tsx) and inject a dashboard border and header.
- Validates URL search parameters (
cityandtech) usingzod. - Uses
loaderDepsto declare search dependencies, ensuring that changes to the URL's query parameters automatically trigger the route loader to filter meetups. - Updates search params using programmatic navigations to filter items cleanly without losing history state.
- Splits files to optimize bundle sizes. Loaders stay in
posts.tsxto run immediately on transition, while heavy UI renders inposts.lazy.tsxwhich is loaded on-demand.
8. Authentication & Route Guards (src/routes/org/activities/meetups/create.tsx, src/routes/login.tsx)
- Implements route-level bouncers inside the
beforeLoadhook. - Unauthorized attempts to visit the create page immediately throw a
redirectto/login, attaching error alerts via search queries. - Maintains login state inside local storage via
src/utils/auth.ts.
- Demonstrates calling
router.invalidate()to clear stale network caches so the list page automatically displays the newly posted meetup.
To run the whole application, you need to start both the mock server and the React app in separate terminal windows.
cd meetup-mock-api
pnpm install
pnpm start- Server will start at: http://localhost:3001
cd meetup-tracker
pnpm install
pnpm dev- Application will run at: http://localhost:3000
Enjoy learning the best routing mechanism available for the modern web! For more details, refer to the official TanStack Router Documentation.
