Chrysolites Tech Academy

Video by freeCodeCamp.org · taught by Tapas Adhikary · streamed from YouTube. All rights remain with the creator.

Lesson 2: Type-Safe Routing in React with TanStack Router

About this lesson

Routing decides what appears on screen for each address in the browser, and in a modern React app it also decides what data loads and who is allowed in. This lesson teaches TanStack Router by building a meetup tracker, set up with the TanStack command-line tool and Vite. It opens with the feature that sets this router apart: full type safety that the tools work out for themselves, so a mistyped link or a missing parameter is flagged in the editor instead of failing in front of a user. You then create pages with file-system routing, where files and folders become routes and shared layouts wrap the pages beneath them. Next comes navigation, both with link components and from code. The lesson shows how lazy routes improve performance by downloading the code for a page only when it is visited. Dynamic routes follow, with loaders that fetch remote data for a page and built-in handling for pending and error states. After that you make search parameters reliable by validating them against a Zod schema. The authentication section passes sign-in state through the router context and protects pages with a check that runs before loading and redirects visitors who are not signed in. You then handle form submissions and refresh stale data by invalidating the router. The lesson closes by comparing this approach with other routing tools. Basic React and some TypeScript are assumed. Afterwards, read Chapter 2 of the course book, which explains the ideas underneath with a route tree diagram, a URL table and a timing chart.

Install Chrysolites Tech Academy

Android / Chrome / Edge: open the browser menu and choose Install app or Add to Home screen.

iPhone / iPad (Safari): tap the Share button, then Add to Home Screen.