Routing
A folder is a URL segment; a [id] folder is a dynamic param.
- /features/routing/42
- /features/routing/hello
- /features/routing/legacy throws
redirect()back here
Routes are type-safe: webjs types (run by
webjs dev) generates a
Route union, and the
[id] page types its props with
PageProps<'/features/routing/[id]'>
so params is checked against the real routes.
Programmatic navigation is checked too:
navigate(url) takes that
Route union, so
navigate('/random/42') is a compile error in
your editor and webjs typecheck. (Plain
<a href> strings are not checked, so
prefer navigate() for internal links you want
verified.)
Changing route in code, two sides:
navigate(url) runs in the browser (a soft,
in-place client-router nav from an event handler, no reload), while
redirect(url) runs on the server (throw it in
a page or an action to bail before render and
return an HTTP 3xx). Throw
redirect() on the server, call
navigate() on the client.
A page can also THROW to short-circuit rendering:
notFound() (404),
forbidden() (403), and
unauthorized() (401), each rendering the
nearest matching boundary file. See the
Boundaries demo.