Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
Tutorial , 2. Pages and routes
Now we give Notes its routes: a list at / and a detail page at /notes/:id. The detail page is a
dynamic route, our first [id] file.
Some seed data
Until we add an API (step 6), keep notes in a plain module so pages have something to show:
The list page
Note the <Link>, in-app navigation, so clicking a note will not reload the page.
The dynamic detail route
Create pages/notes/[id].tsx. The [id] in the filename becomes the route /notes/:id, and useParams()
gives us the id:
Register both routes
server.tsx maps patterns to modules. Add the import and the mapping:
The scanRoutes loop already registers anything in modules, so no other change is needed. (Recall:
scanRoutes returns the pattern /notes/:id for the file pages/notes/[id].tsx.)
Dynamic routes render on the client
/notes/:id is a dynamic route, so the server returns a shell and the page renders on the client using
params. The ssr() still sets the title. This is exactly the behaviour described in
Dynamic routes, the body depends on the URL, so it is not pre-cached.
Run and click around
/lists the two seed notes.- Clicking one navigates to
/notes/welcomewithout a reload (watch, no flash; the header stays put). - A bad id (
/notes/nope) shows the "not found" branch.
A little CSS
Restart the server to pick up SCSS changes.
Next: a richer shell and shared chrome, 3. Layouts.