/tasks/:id, then navigate({ to: '/tasks/:id', params: { id: 'abc' } }) compiles but navigate({ to: '/bogus' }) doesn’t.
Define routes
UsedefineRoutes() to declare your route map:
component factory.
Dynamic segments
Use:param in the path for dynamic segments:
Create the router
Pass your routes tocreateRouter():
popstate events and matches the current URL against your routes.
Render with RouterView
RouterView renders the matched route’s component and handles transitions:
RouterView handles:
- Sync and async (lazy-loaded) components
- Stale resolution guards — if a slow route resolves after a newer navigation, it’s discarded
- Automatic cleanup of the previous page
Navigate between pages
useRouter()
Pages access navigation via context — no prop threading:Typed navigation
Scaffolded apps get typeduseRouter() automatically after codegen runs:
navigate() is constrained to valid route patterns and params:
.vertz/generated/router.d.ts. If you build a
project by hand, make sure .vertz/generated is included in tsconfig.json.
Replace vs push
Use{ replace: true } to replace the current history entry instead of pushing:
Access route params
UseuseParams() to access typed route parameters:
useParams<'/tasks/:id'>()returns{ id: string }useParams<'/users/:userId/posts/:postId'>()returns{ userId: string; postId: string }
Param validation with schemas
Routes can validate and parse params at the routing layer using aparams schema:
params schema:
- Valid params are parsed and available via
useParams()with the parsed types - Invalid params (e.g.,
/tasks/not-a-uuid) don’t match the route — the fallback renders instead
Nested routes
Usechildren for layout routes with nested pages:
Outlet to render the matched child:
Pre-rendering (SSG)
Routes can be pre-rendered to static HTML at build time. Addprerender: true for static routes, or generateParams for dynamic routes:
vertz build, routes with prerender: true or generateParams are rendered to dist/client/<path>/index.html. See the SSG guide for details.
Lazy-loaded routes
Return a dynamic import fromcomponent for code splitting: