Skip to content
Tutorials Center
My learning

Topics

React Router Tutorial

Learn React Router 7 from your first route to nested layouts, params, loaders and actions, protected routes, lazy loading, framework mode and testing. 50 lessons with examples, quizzes and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is React Router? Learn what React Router does, why single-page apps need a router, how version 7 merged with Remix, and what declarative, data and framework mode mean.
  2. 2 Installing and Your First Routes Install React Router 7 in a Vite project, wrap the app in BrowserRouter and build a two-page app with Routes, Route and Link, plus a runnable stand-in.
  3. 3 How Routing Works Under the Hood See how React Router really works: the History API, pushState, popstate, the location object, the server fallback to index.html and hash routing.
  4. 4 Choosing Between Declarative, Data and Framework Mode Compare React Router 7's declarative, data and framework modes, learn which imports each uses, how to upgrade between them and how to pick the right one.

Declarative Routing Basics

  1. 5 Routes and Matching Learn how React Router matches URLs to routes: path patterns, params, splats, specificity ranking, index routes, trailing slashes and case sensitivity.
  2. 6 Link and NavLink Learn how React Router's Link differs from a plain anchor, how the to prop works, and how NavLink styles active links with className, style, end and aria-current.
  3. 7 404 Pages and Catch-All Routes Build a 404 page with a path=* route, read splat params, put a not-found inside a layout, and learn why single-page apps need extra work to send a real 404 status.
  4. 8 Routes as Objects: useRoutes and Route Configs Describe React Router routes as plain objects with useRoutes or createRoutesFromElements, compare them with JSX, and share one route config across router modes.
  5. 9 Redirects with Navigate Redirect old URLs, index routes and logged-out users with the Navigate component, understand push versus replace, keep splats, and avoid redirect loops.

Nested Routes and Layouts

  1. 10 Nested Routes and Outlet Nest routes inside parent routes, render children with Outlet, map a URL to a tree of layouts, and see why parent layouts stay mounted between pages.
  2. 11 Layout Routes and Pathless Routes Share headers, sidebars and guards between pages with layout routes that add no URL segment: pathless routes, several layouts in one app and route groups.
  3. 12 Passing Data Down with Outlet Context Pass state from a layout route to its child pages with the context prop of Outlet and useOutletContext, and learn when a loader or React context fits better.
  4. 13 Relative Links and Relative Routing Learn how React Router resolves relative links: route-relative versus path-relative, what '..' really means, and the pitfalls in nested layouts.

Params and Search Params

  1. 14 Dynamic Segments and useParams Learn dynamic segments in React Router: :id params, optional segments, splats, decoding, TypeScript types and how to validate params safely.
  2. 15 Search Params and useSearchParams Read, update and validate the query string with useSearchParams: functional updates, repeated keys for arrays, defaults, and filters that live in the URL.
  3. 16 Putting UI State in the URL Decide what belongs in the URL and learn the patterns: tabs, sorting, pagination, modals, debounced search, defaults, shareable links and push versus replace.
  4. 17 useLocation and Navigation State Understand the location object: pathname, search, hash, key and navigation state. Learn to pass state with links and return users to the previous page.

Navigating Programmatically

  1. 18 useNavigate and Imperative Navigation Use useNavigate to change pages from code: navigate(to), back and forward with deltas, replace, state, redirects after a form submit, and what to avoid.
  2. 19 Protected Routes and Auth Redirects Build protected routes in React Router: an auth context, a guard layout route, redirect to login with a from location, role checks, and why client guards are not security.
  3. 20 Blocking Navigation Stop users from losing work: use React Router's useBlocker for in-app navigation, beforeunload for tab closes, and learn the pitfalls of unsaved form changes.

Data Mode

  1. 21 createBrowserRouter and RouterProvider Enter data mode: create a router with createBrowserRouter, describe routes as objects, render it with RouterProvider, and migrate an app from BrowserRouter.
  2. 22 Loaders: Data Before Render Learn React Router loaders: fetch data before a route renders, read it with useLoaderData, use params and request, load nested routes in parallel and throw responses.
  3. 23 Actions and Form Handle form submissions with React Router actions: the Form component, request.formData(), validation with useActionData, redirect after submit and automatic revalidation.
  4. 24 useFetcher and Inline Mutations Use useFetcher to submit forms and load data without navigating: fetcher.Form, fetcher.submit, fetcher.load, optimistic UI from formData and concurrent mutations.
  5. 25 Pending and Optimistic UI Show progress bars, pending links and saving states with useNavigation and fetcher state, and make forms feel instant with optimistic updates in React Router.
  6. 26 Streaming Data with Await and Suspense Return promises from React Router loaders, render them with Await and Suspense, handle failures with errorElement, and learn which data should be streamed.
  7. 27 Revalidation and Caching Learn when React Router re-runs loaders, skip needless refetches with shouldRevalidate, refresh stale data with useRevalidator, and pair loaders with TanStack Query.
  8. 28 Error Boundaries and Error Elements Handle loader, action and render errors with errorElement, read them with useRouteError and isRouteErrorResponse, nest boundaries, and send 404s from loaders.
  9. 29 Lazy Routes and Code Splitting Split your app into per-route bundles with route.lazy and React.lazy, preload pages on hover, avoid layout flashes, and handle chunk load failures in React Router.

Production Concerns

  1. 30 Scroll Restoration, Focus and Page Titles Restore scroll positions with ScrollRestoration and getKey, move focus and announce page changes for screen readers, and set a document title for every route.
  2. 31 Route Handles and Breadcrumbs Attach metadata to routes with the handle property, read the whole match chain with useMatches, and build breadcrumbs, page titles and layout switches from it.
  3. 32 Modal Routes and Background Locations Give a modal its own URL: open it over the current page with a background location, deep-link to it, close it with the back button, and compare nested-route modals.
  4. 33 Authentication with Loaders and Actions Protect routes with loaders that redirect, sign in and out with actions, keep sessions in HttpOnly cookies, and learn why guards alone never protect your data.
  5. 34 Performance and Common Pitfalls Find out what re-renders when the URL changes, avoid loader waterfalls and needless revalidation, handle big route trees, and fix key and stale-link bugs.

Framework Mode

  1. 35 Framework Mode Overview Meet React Router framework mode: the Vite plugin, react-router.config.ts, root.tsx, entry files, and the choice between SSR, SPA mode and prerendering.
  2. 36 Route Config and File Routes Describe framework-mode routes in routes.ts with route(), index(), layout() and prefix(), or derive them from file names with flatRoutes, and use generated types.
  3. 37 Server Loaders, Client Loaders and Actions Learn how framework-mode loaders run on the server, when to use clientLoader, how to keep secrets out of the browser, set cookies and sessions, and export meta, links and headers.
  4. 38 SSR, Streaming and Deployment Understand server rendering in React Router framework mode: streaming with Await, prerendering, SPA mode, deploying to Node, Cloudflare or static hosts, SEO basics and Remix upgrades.

Testing

  1. 39 Testing Routes and Components Test React Router apps with Testing Library: render at any URL with MemoryRouter, createMemoryRouter and createRoutesStub, then check links, loaders, actions and errors.

Projects

  1. 40 Project: A Multi-Page Site with Nested Layouts Build a small multi-page site step by step: a route table, active navigation links, nested layouts with Outlet, URL params, breadcrumbs, page titles and a 404 inside the layout.
  2. 41 Project: A Blog with Loaders and Search Params Build a blog with a post list, post pages, tag filters, search and pagination stored in the URL, loader-style data fetching, pending UI and nested error boundaries.
  3. 42 Project: An Admin Dashboard with Protected Routes Build an admin dashboard with a login page, a guard layout route, nested sections, role-based pages, return-to-page redirects and logout, plus why server checks matter.
  4. 43 Project: A Notes App with Actions and Optimistic UI Build a notes app around loaders and actions: list, create, edit and delete notes, show pending states, handle validation and server errors, and update the screen optimistically.
  5. 44 Project: A Product Catalog with Filters and a Cart Build a shop with React Router ideas: filters and sorting stored in the URL, product detail routes, a cart that survives navigation, and a deep-linkable quick-view modal route.

Practice and Review

  1. 45 Exercises: Declarative Routing Eight graded React Router exercises on route matching, links, params and nested layouts. Four are runnable test-driven functions, four are real-code design tasks, all with solutions.
  2. 46 Exercises: Data Mode Eight React Router data mode exercises on loaders, actions, pending UI, optimistic updates, error boundaries and revalidation. Four runnable, four real-code, all with solutions.
  3. 47 Migrating From v5, v6 and Remix Upgrade an existing app to React Router 7: replace Switch and useHistory, move from v6 with future flags to v7, and port a Remix app to framework mode, step by step.
  4. 48 Common Mistakes and Debugging The routing bugs everyone hits: missing Outlet, relative links that go to the wrong place, hooks outside a Router, stale loader data, redirect loops, and how to inspect routes.
  5. 49 React Router Interview Questions 25 React Router interview questions with concise answers: routing modes, nested routes, params, loaders, actions, fetchers, errors, auth and testing, plus runnable stand-in demos.
  6. 50 React Router Cheat Sheet A one-page React Router v7 cheat sheet: route patterns, components, hooks, loader and action APIs, data router config and framework mode files, with runnable stand-in demos.