Advanced React 07 · Ecosystem
Routing (React Router)
Pages, parameters, nested layouts, state in the URL, loaders and protected routes.
Loading lesson…
Advanced React 07 · Ecosystem
Pages, parameters, nested layouts, state in the URL, loaders and protected routes.
Loading lesson…
A single-page application (SPA) is one single HTML page. If it stayed that way, the whole app would have one address – and the user couldn't send a colleague a link to a specific product, bookmark a page or go back with the Back button. That's why we need every "screen" to have its own address, even though it's still one page.
Imagine the app as a hotel:
/products/42 = "second floor, room 42". Whoever knows the number gets straight there.<Outlet /> component.?view=sea&cot=yes. Still the same room, just prepared differently.A simple rule: as soon as the app has several screens you want to link to. The table shows what goes where; the section where you'll learn it is on the right:
| Situation | Solution | Section |
|---|---|---|
| one screen, nothing is shared | no router needed | — |
| several pages with their own address (home, products, detail) | routes, Link, :parameter, layout | 1 |
| a filter, sorting, a results page, a search text | search params | 2 |
| a page needs data as soon as it opens | a loader | 3 |
| a page for signed-in users only | a doorman: a layout route with Navigate | 4 |
| parts of the app with their own menu (website, app, settings) | several layouts inside each other, some without a path | 5 |
| an open dialog, half-typed text, the mouse hovering over something | useState | lesson React basics 03 |
/products/42 → a parameter) and how to show it (?sort=price → search params).The router isn't part of React – it's a separate library, React Router. You add it to a project with npm install react-router (packages from JavaScript 08).
A small shop: a home page, a product list, a product detail and a "not found" page.
import { createRoot } from 'react-dom/client'import { createBrowserRouter, RouterProvider, Outlet, Link, useParams } from 'react-router'// The list of routes: an array of objects, each saying "at this address show this component"const router = createBrowserRouter([{path: '/',element: <Layout />, // the corridor – visible on every pagechildren: [ // rooms = the pages inside the corridor// The home page "/". Instead of path it has index: true = "the default room":// it shows when there's nothing after the "/".{ index: true, element: <Home /> },// The product list at "/products".{ path: 'products', element: <ProductList /> },// The detail at "/products/3", "/products/42"… The colon means "anything can go// here". Whatever is there in the address, ProductDetail reads under the name productId.{ path: 'products/:productId', element: <ProductDetail /> },// Any other address → the "not found" page.{ path: '*', element: <NotFound /> },],},])// RouterProvider: instead of <App /> you render the router; it picks the page by the addresscreateRoot(document.getElementById('root')!).render(<RouterProvider router={router} />)function Layout() {return (<><nav><Link to="/">Home</Link><Link to="/products">Products</Link></nav><Outlet /> {/* the room door */}</>)}
The user clicks a link leading to /products/3. What the reception does:
<Link> doesn't cause a page reload. It just changes the address in the browser and lets the router know./ matches the start of the address → it renders Layout. In its children it finds products/:productId, which matches the rest, and remembers productId = "3".Layout renders with the navigation, and ProductDetail appears in place of <Outlet />. The navigation stayed the same – only the room changed.ProductDetail we find out the room number with useParams():function ProductDetail() {const { productId } = useParams() // "3" – always TEXT, not a number!// products = the array of all products (the shop's made-up data)const product = products.find((p) => p.id === Number(productId))if (!product) return <p>Product not found</p>return <h2>{product.name}</h2>}
The number on a room door is always written – the address is text, so productId is the text "3" too, not the number 3. Hence Number(productId).
In the demo below, the navigation uses Link's sibling NavLink instead. It works the same, but it also knows whether you're on its address right now – so you can highlight the button of the current page:
<nav>{/* className here isn't text but a function. The router calls it and tells itwhether the link is active (isActive). You return a class based on that. */}<NavLink to="/" end className={({ isActive }) => (isActive ? 'active' : '')}>Home</NavLink><NavLink to="/products" className={({ isActive }) => (isActive ? 'active' : '')}>Products</NavLink></nav>
What you see: The shop from the example above. At the top, a fake address bar with Back/Forward arrows, under it the navigation (the layout) and in the card the content of the current page (<Outlet />).
Try it:
/products, the button is highlighted (that's what NavLink can do) and the card shows the list. The navigation at the top stayed.* takes over and a 404 appears.The takeaway: Every screen has its address, the layout doesn't change and only the content in <Outlet /> changes. And all without reloading the page.
Loading the interactive part…
A link isn't enough when you need to go somewhere else from code – say, after a form is sent. That's what the useNavigate hook is for. It returns a function you give an address to:
function NewProductForm() {const navigate = useNavigate() // a function for going elsewhere// you call navigate() in an event handler – here after a click on the buttonasync function handleSubmit() {const id = await saveProduct() // a made-up function: saves the product and returns its idnavigate(`/products/${id}`) // after saving, go to the new product's detail}return <button onClick={handleSubmit}>Save the product</button>}
navigate() belongs only in event handlers (a click, a form being sent). When the redirect is decided already while rendering – say "a signed-out user can't be here" – there's a different tool for it. We'll show it in section 4 with protected pages.
The table sums up everything React Router offers in this lesson; the name on the left, what it's for on the right. You'll see Navigate and useLocation in section 4:
| API | What for |
|---|---|
<Link to> | Navigation without reloading the page. Relative paths are resolved against the current route. |
<NavLink> | A Link that knows it’s active (menus, tabs). |
<Outlet /> | The place in a layout where a nested route renders. |
useParams() | The variable parts of the address (:id). Always text – convert them! |
useNavigate() | Navigation from code (after submitting a form, after signing in). |
<Navigate to replace /> | A redirect during render (protected pages). |
useLocation() | The current address: pathname, search, state. |
When you book a hotel room "with a sea view and a cot", you want that to still hold tomorrow, and you want a colleague you send the booking to to get the same. So the requests belong in the booking, not in your head.
Filters, sorting, paging, a search term – these are all requests about a page's content. If they were only in useState, they would disappear after a reload and a colleague opening the link would see something else. So they belong in the search params – the part of the address after the question mark: /products?category=fruit&sort=price.
The parameters after the question mark are name=value pairs separated by &. The browser has a built-in URLSearchParams object for them with three methods, similar to the Map from Hooks 02:
const params = new URLSearchParams('category=fruit&sort=price')params.get('category') // → "fruit"params.get('colour') // → null (no such parameter)params.set('sort', 'name') // change the value (or add it if it isn't there)params.delete('category') // remove the parameterparams.toString() // → "sort=name"
React Router adds the useSearchParams hook, which reads the parameters from the address and can write them into it:
function Catalog() {const [searchParams, setSearchParams] = useSearchParams() // like useState: [values, function to change them]// Reading: a missing value is nullconst category = searchParams.get('category') // "fruit" | nullconst sort = searchParams.get('sort') ?? 'name' // ?? = if it's missing, use 'name' (here we only read the sorting)// Writing: you give the setter an object with the parameters that should be in the addressfunction setCategory(value: string | null) {if (value) setSearchParams({ category: value }) // "fruit" → /products?category=fruitelse setSearchParams({}) // null ("All") → /products, no parameters}const visible = products.filter((p) => !category || p.category === category)return (<><button onClick={() => setCategory(null)}>All</button><button onClick={() => setCategory('fruit')}>Fruit</button><ul>{visible.map((p) => <li key={p.id}>{p.name}</li>)}</ul></>)}
useSearchParams works much like useState: it returns the current values and a function to change them. Only the "notebook" is the address.setSearchParams changes the address and the component re-renders – category then reads the new value.!category || p.category === category: when no category is picked, every product passes; when one is, only products from it (operators from JavaScript 06).But there's a catch. The object replaces all the parameters in the address – whatever isn't in it disappears. When the user sorted the products by price and then picks a category, the sorting is lost:
// the address is now /products?category=fruit&sort=pricesetSearchParams({ category: 'vegetables' }) // → /products?category=vegetables (sort is gone!)
We need to change only the category and leave the rest as it is. For that we need to know what's in the address now. So instead of an object we give the setter a function – just like with state in React basics 04. React Router calls it, passes it the current parameters, and whatever the function returns becomes the new address:
function setCategory(value: string | null) {setSearchParams((prev) => { // prev = the current parameters: category=fruit&sort=priceconst next = new URLSearchParams(prev) // 1. a copy: category=fruit&sort=priceif (value) next.set('category', value) // 2. "vegetables" → category=vegetables&sort=priceelse next.delete('category') // null ("All") → sort=pricereturn next // 3. this becomes the new address – the sorting stayed})}
prev is a URLSearchParams object with everything that's after the question mark now.new URLSearchParams(prev) makes a copy of it – a new object with the same pairs. Why not just change prev with prev.set(…) and return it? For the same reason as with state: you don't change the previous value, you make a new one.set sets it (or adds it), delete removes it. The other pairs stayed in it.A simple rule: an object when only what you write into it should stay in the address; a function with a copy when you change one parameter and the others should stay.
Every call of setSearchParams adds a new step to the browser history, so the Back button returns the previous filter. For a search, though, every letter would be one step. That's why it gets the replace option, which just overwrites the current step. Options go in as the setter's second argument:
// in the onChange handler of the search field (text = what the user typed)setSearchParams((prev) => {const next = new URLSearchParams(prev) // a copy – the category and sorting staynext.set('q', text)return next},{ replace: true }, // a new address without a new step in the history)
What you see: A catalogue with a search, categories and sorting. All three filters live only in the address – watch the address bar at the top. The demo starts at the address /?category=fruit, as if someone had sent it to you.
Try it:
q parameter changes with every letter, but it doesn't clutter the history (the code uses replace).The takeaway: State in the address survives a reload, can be sent as a link and works with the Back and Forward buttons. The component just reads it and calculates from it.
Loading the interactive part…
In a bad hotel they send you to your room and the housekeeper starts cleaning only when you walk in. You wait in the doorway. In a good hotel the room is ready before you walk in.
This is what a product detail looks like without a loader. The component loads the data itself, in an effect from Hooks 01:
// ✗ without a loader: the room gets cleaned only once you walk infunction ProductPage() {const { productId } = useParams()const [product, setProduct] = useState<Product | null>(null) // Product = the product type; null = nothing yetuseEffect(() => {// fetchProduct = a made-up function: downloads the product from the serverfetchProduct(Number(productId)).then((p) => setProduct(p)) // starts only AFTER the first render}, [productId])if (!product) return <p>Loading…</p> // this is what the user sees firstreturn <h2>{product.name}</h2>}
The user clicks and gets an empty page with "Loading…". And when the page has nested parts, each starts loading only after its parent – the waiting adds up (a so-called waterfall). A loader is the housekeeper: the router calls it before rendering the page and the component gets the data ready.
Four pieces work with loaders. Here they all are together – the same shop as in section 1, only the product detail now downloads its data from the server:
import { createBrowserRouter, Outlet, useLoaderData, useNavigation, useRouteError,isRouteErrorResponse, type LoaderFunctionArgs } from 'react-router'// 1. THE HOUSEKEEPER (loader): an ordinary async function the router calls before it shows the page// LoaderFunctionArgs = the type of what the loader gets from the router (params = the variable parts of the address)async function productLoader({ params }: LoaderFunctionArgs) {const product = await fetchProduct(Number(params.productId)) // returns the product, or nullif (!product) throw new Response('Product not found', { status: 404 }) // "no such room" → 3.return { product } // this is what the component gets (2.)}// 2. THE ROOM (component): no useEffect, no "Loading…" – the data is already therefunction ProductPage() {// useLoaderData returns what the loader returned; <typeof productLoader> = take the data's type from the loaderconst { product } = useLoaderData<typeof productLoader>()return <h2>{product.name}</h2>}// 3. THE RECEPTIONIST FOR PROBLEMS (errorElement): shown instead of the room when the loader throws an errorfunction ErrorPage() {const error = useRouteError() // whatever the loader threw with throw// isRouteErrorResponse: is it a Response (like the one with 404)? Then it has a status and text.if (isRouteErrorResponse(error)) {return <h2>{error.status} – {error.data}</h2> // "404 – Product not found"}return <h2>Something went wrong.</h2>}// 4. THE CORRIDOR WITH A NOTICE: while the housekeeper prepares the next room, let the guest knowfunction Layout() {const navigation = useNavigation() // navigation.state: 'idle' (nothing) | 'loading' (loading)return (<>{navigation.state === 'loading' && <p>Loading the next page…</p>}<Outlet /></>)}// PUTTING IT TOGETHER: in the routes list you give the room a housekeeper (loader) and a receptionist for problems (errorElement)const router = createBrowserRouter([{path: '/',element: <Layout />, // 4.children: [{ index: true, element: <Home /> }, // Home from section 1{path: 'products/:productId',loader: productLoader, // 1.element: <ProductPage />, // 2.errorElement: <ErrorPage />, // 3.},],},])
What happens when the user clicks a link to /products/3:
products/:productId and calls its loader (1.) with params.productId = "3". The old page stays visible for now.navigation.state equals 'loading', so the corridor (4.) shows "Loading the next page…".ProductPage (2.) takes the ready product with useLoaderData.Response with 404 and ErrorPage (3.) shows instead of ProductPage – the reception says "we don't have a room like that".new Response(text, { status }) is the same object fetch returns (JavaScript 07). With it the loader "plays the server" and says: this page doesn't exist. The router recognises it and hands it to the error page.
What you see: A product list and a detail, both with a loader. The fake API replies with a delay. During navigation "Loading the next page…" appears above the card.
Try it:
The takeaway: The data is loaded before rendering. The component only handles the display, and errorElement takes care of errors.
Loading the interactive part…
In tutorials on the internet you'll meet React Router written differently too. The library has three modes; this course uses the middle one ("Data"), because only it has loaders. The table helps you tell which mode you're looking at:
| React Router mode | What it is | When |
|---|---|---|
| Declarative | <BrowserRouter> + <Routes>/<Route> in JSX | Simple apps, gradual migration. |
| Data | createBrowserRouter + loader/action/errorElement | SPAs where you want data loading tied to routes. |
| Framework | A Vite plugin, file-based routes, SSR (rendering on the server), typegen (automatically generated types) | New full-stack apps – front end and server (the successor of the Remix framework). |
You can't just walk onto a hotel's VIP floor – there's a doorman by the lift. If you don't have a key card, they send you to the reception, which notes down where you wanted to go. Once that's sorted, they send you straight there.
In an app, a doorman like this is called a route guard – you'll meet the term in tutorials and in the documentation. It isn't any special feature of React Router but an ordinary component you write yourself. It does just two things:
<Outlet />) or redirects the guest to sign in (<Navigate />, explained right below the code example).You plug it into the list of routes as a layout route: a route that has children and renders them in its <Outlet /> – just like the Layout corridor from section 1. The doorman differs in one thing only: it has no path, so it adds nothing to the address. The protected pages keep their addresses and the doorman just stands “between” the corridor and them:
function RequireAuth() {const { user } = useAuth() // a made-up hook over a sign-in context (like useTheme in Hooks 04); user = null when nobody is signed inconst location = useLocation() // where we are now: location.pathname = "/account/settings"if (!user) {// to the reception – and note down where the guest wanted to go (encodeURIComponent: see the box below)return <Navigate to={`/login?redirect=${encodeURIComponent(location.pathname)}`} replace />}return <Outlet /> // let them through}// A route without a path: adds nothing to the address, just wraps its children (also in the routes array in createBrowserRouter){ element: <RequireAuth />, children: [{ path: 'account', element: <Account /> },{ path: 'account/settings', element: <Settings /> },]}
<Navigate to="…" /> is a component that redirects to another address as soon as it renders. It's used where the redirect is decided during render – right in the component's body, not after a click. Why isn't navigate() from section 1 enough here?
// ✗ not like this: navigate() right in the component's body = during renderfunction RequireAuth() {const { user } = useAuth()const navigate = useNavigate()if (!user) navigate('/login') // React Router only logs a warning and redirects nowherereturn <Outlet /> // … and the signed-out guest sees the protected page}// ✓ like this: return <Navigate /> during renderfunction RequireAuth() {const { user } = useAuth()if (!user) return <Navigate to="/login" replace /> // redirects right after renderingreturn <Outlet />}
Rendering should only say what to show – it shouldn't change anything. Going elsewhere is a change, and that belongs in an event handler (like handleSubmit in section 1). <Navigate /> gets around it cleverly: during render you just return it as a piece of the screen, and the redirect happens only after rendering.
replace makes sure the redirect isn't written into the history – the Back button then doesn't lead to the doorman again.
The second half is left: the reception. When the guest signs in, they should end up where they originally wanted to go, not on the home page. The reception reads the target from the address (search params from section 2) and after a click on “Sign in” sends the guest there with the navigate function:
function LoginPage() {const { login } = useAuth() // the same made-up hook as in the doorman; login(name) signs the guest inconst navigate = useNavigate()const [searchParams] = useSearchParams()// where the guest wanted to go: "/account/settings" (get decodes the encoded address by itself), or null when they came directly// ?? = when the left side is null, take the right side (the JavaScript 01 lesson) – then they end up on the account pageconst redirect = searchParams.get('redirect') ?? '/account'function handleLogin() {login('Anna') // the guest is signed innavigate(redirect, { replace: true }) // and goes where they wanted; the reception is replaced by the target in the history}return <button onClick={handleLogin}>Sign in</button>}
Here navigate() is right: moving elsewhere happens after a click, in an event handler, not during rendering. You know { replace: true } from section 2 – the new address replaces the current one instead of adding another step to the history.
The whole trip of a guest who wants to open the account settings looks like this:
/account/settings. The router finds the route under the doorman, so it renders RequireAuth first.<Navigate replace /> and the address changes to /login?redirect=%2Faccount%2Fsettings. Thanks to replace, only the reception stays in the history instead of the settings.redirect from the address. After a click on “Sign in” it signs the guest in and sends them to /account/settings – again with replace, so the reception is replaced in the history too.<Outlet /> and the settings show.So neither the doorman nor the reception stayed in the history: the Back button leads where the guest was before clicking the link.
In a real app the doorman gets a file of its own, just like every page. You export it from that file with export and import it in the file with the list of routes (modules from the JavaScript 08 lesson):
// file src/RequireAuth.tsx – the doorman in a file of its ownimport { Navigate, Outlet, useLocation } from 'react-router'import { useAuth } from './auth' // a made-up file with the sign-in context (as in the Hooks 04 lesson)export function RequireAuth() { // export = it can be imported in another fileconst { user } = useAuth()const location = useLocation()if (!user) return <Navigate to={`/login?redirect=${encodeURIComponent(location.pathname)}`} replace />return <Outlet />}
// file src/main.tsx – the list of routes; it just imports the doorman and puts it in front of the protected pagesimport { RequireAuth } from './RequireAuth'import { Account } from './Account' // the pages have a file each tooimport { Settings } from './Settings'const router = createBrowserRouter([{ path: '/', element: <Layout />, children: [{ element: <RequireAuth />, children: [ // the doorman guards everything inside{ path: 'account', element: <Account /> },{ path: 'account/settings', element: <Settings /> },]},]},])
Why separately, and not a piece of code in every page?
children – you don't have to write anything in the page and you can't forget the check.Account just shows the account; whether the guest may be there is someone else's job. Every file has one job.You can try all of it in the demo now – the doorman guards the hotel's VIP floor from the start of this section. In the demo everything is in one file so you can read the code in one go; in an app the doorman, the reception and the pages would each have their own.
What you see: A hotel with three places: everyone may see the lobby, the doorman guards the VIP bar and the VIP spa. At the top is a fake address bar with the Back and Forward arrows.
Try it:
/login?redirect=%2Fvip%2Fspa – the doorman noted where you wanted to go.redirect=%2Fvip%2Fbar.The takeaway: One doorman (a layout route without a path) guards both VIP pages at once, and thanks to redirect in the address the reception knows where to send the guest back after signing in.
Loading the interactive part…
In the second challenge you build the same for the account pages and add two more things: what to do when a signed-in user opens the sign-in page, and where to send them after signing out.
This section puts the lesson together into a template to come back to when you set up an app with several pages. You'll find the same pattern in the Cheat sheets on the React tab.
// the file src/main.tsx – the start of an app with pagesimport { createRoot } from 'react-dom/client'import { createBrowserRouter, RouterProvider } from 'react-router'// Layout, Home, Catalog, ProductPage, productLoader, RequireAuth, Account, NotFound and ErrorPage// are your components and functions – each in its own file, imported here (as in sections 1 to 4)const router = createBrowserRouter([{path: '/',element: <Layout />, // the corridor: a menu + <Outlet />errorElement: <ErrorPage />, // when anything goes wrong (a 404 from a loader too)children: [{ index: true, element: <Home /> }, // exactly "/"{ path: 'products', element: <Catalog /> }, // the filter in ?category={ path: 'products/:productId', loader: productLoader, element: <ProductPage /> }, // data in advance{ element: <RequireAuth />, children: [ // the doorman{ path: 'account', element: <Account /> },]},{ path: '*', element: <NotFound /> }, // anything else],},])// render the router instead of <App /> – it picks the page by the addresscreateRoot(document.getElementById('root')!).render(<RouterProvider router={router} />)
The template above has one layout for all pages. A bigger app often has several: the public website has its own menu, the app after signing in its own bar, and the settings a side menu on top of that. You don't need any new building block for it – you only combine two you already know: a layout route with <Outlet /> (the corridor from section 1) and a route without a path (like the doorman from section 4).
Before you write any code, draw which parts of the screen repeat on which pages. Every place where something repeats becomes one layout:
app├── public website – website menu (PublicLayout)│ ├── Home /│ └── Pricing /pricing└── app – app bar (AppLayout)├── Dashboard /dashboard└── settings – plus a side menu (SettingsLayout)├── Profile /settings└── Password /settings/password
The list of routes just copies the drawing – every branch is a route, every layout has children:
const router = createBrowserRouter([{element: <PublicLayout />, // no path: adds nothing to the address, just wraps the website pageschildren: [{ path: '/', element: <Home /> },{ path: '/pricing', element: <Pricing /> },],},{element: <AppLayout />, // no path: wraps the app pageschildren: [ // (for signed-in users you'd wrap it in the doorman from section 4 too){ path: '/dashboard', element: <Dashboard /> },{path: '/settings', // this layout has a path: everything under it starts with /settingselement: <SettingsLayout />,children: [{ index: true, element: <Profile /> }, // exactly /settings{ path: 'password', element: <Password /> }, // /settings/password],},],},])
Every layout is an ordinary component with a menu and one <Outlet /> – just like the Layout corridor from section 1. What happens at the address /settings/password:
AppLayout (no address) → /settings → password.AppLayout puts SettingsLayout into its <Outlet />, and that one puts the Password page into its <Outlet />./settings): both outer boxes stay, only the innermost one is swapped./): that's a different branch of the tree, so the whole wrapper is swapped – the website menu instead of the app bar.What you see: Every layout here draws a dashed frame with its name, so you see which layers were rendered for the current address. At the top is a fake address bar.
Try it:
The takeaway: Each layer handles one part of the screen and is swapped only when its branch of the tree changes. The pages don't know about the menus – they only have their content.
Loading the interactive part…
A simple rule for which layout when:
<Outlet />, the pages as its children. Don't copy the menu into every page./settings/…) → the layout gets a path. They don't (the website and the app) → a layout without a path.Link, not <a href>.Number(id)) and handle finding nothing.replace and a noted way back.errorElement.Two pages, two links. Watch how the address at the top changes.
Task is in the comments in the code below – at the top of the file and at the places marked TODO.
Loading the interactive part…
The mini e-shop practises sections 1 and 2: a layout, a list, a detail, a filter in the address and a 404. The protected pages complete section 4 – the doorman and the return to where the user originally wanted to go.
The complete routing of a small app: a layout, a list, a detail, state in the address and a 404. What should happen is in the comments in the code.
Medium and hard challenges unlock once you sign in. Like the whole course, they are free – just an e-mail, no password and no payment.
A pattern you'll find in every app with sign-in: a doorman + a return to where the user originally wanted to go. What should happen is in the comments in the code.
Medium and hard challenges unlock once you sign in. Like the whole course, they are free – just an e-mail, no password and no payment.
<Outlet /> = a shared layout.Link/NavLink in JSX, useNavigate in handlers, <Navigate /> during render. Never <a href>.errorElement handles errors and 404s.<Navigate replace> to the sign-in and back again.createMemoryRouter, Link, Outlet, RouterProvider, AddressBar)createMemoryRouter, Link, Outlet, RouterProvider – from the library react-router: the routing library (lesson Advanced React 07).AddressBar – from the file src/lessons/03-react-advanced/07-routing/demos/AddressBar.en.tsx. A fake address bar. The demos run in a memory router, so you wouldn't see the URL otherwise./** A fake address bar – the demos run in a memory router, so let's show the URL. */export function AddressBar() {const location = useLocation()const navigate = useNavigate()return (<div className="row" style={{ marginBottom: 12 }}><button className="btn btn-small btn-ghost" onClick={() => navigate(-1)} aria-label="Back">←</button><button className="btn btn-small btn-ghost" onClick={() => navigate(1)} aria-label="Forward">→</button><code style={{ flex: 1, padding: '0.3rem 0.6rem' }}>https://shop.example{location.pathname}{location.search}</code></div>)}
row, stack, card, list, btn, input or muted are the course's ready-made styles in src/styles.css (row = side by side, stack = stacked, card = bordered box, muted = grey text).