Routing and application structure
Routes are part of your information architecture, not an afterthought.
What you will be able to do
- Use nested routes for shared layouts such as a dashboard shell.
- Keep route parameters in the URL when the view should be shareable.
- Add a not-found route and an error boundary.
In plain English
React Router maps URLs to components. A useful structure separates pages from reusable UI, keeps data loading near the route and provides a real 404. URLs should be shareable and survive a refresh.
import { createBrowserRouter } from 'react-router-dom'
import Dashboard from './Dashboard'
import Lesson from './Lesson'
import NotFound from './NotFound'
export const router = createBrowserRouter([
{ path: '/', element: <Dashboard /> },
{ path: '/lessons/:slug', element: <Lesson /> },
{ path: '*', element: <NotFound /> },
])Your turn
MediumAdd a lesson route
Add a route /lessons/:slug that renders a Lesson component and a wildcard 404.
JSX · starter
const router = createBrowserRouter([
{ path: '/', element: <Home /> },
])Check your understanding before moving on.
Knowledge checkQuestion 1
What does a wildcard route usually provide?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.