Function: route()
route(
name,path,page,config?):Route
Creates a Route definition.
Maps a URL path to a Page. Paths support React Router patterns
such as dynamic segments (/tasks/:id), optional segments
(/photo/:id/edit?), and splats (/files/*).
Use config.prerender to render the route to static HTML at build time:
true prerenders the route's own static path, or pass an array of concrete
paths to prerender specific instances of a dynamic route (see
Prerendering). Use
config.lazy to opt out of lazy-loading the page's bundle.
Parametersโ
nameโ
string
Unique name for the route.
pathโ
string
URL path the route matches.
pageโ
The result of page().
config?โ
Optional route settings (lazy, prerender).
lazy?โ
boolean
Lazy-load the page's component.
Set to false to include the page in the initial client bundle, which
avoids the brief loading delay on first navigation at the cost of a larger
initial download.
Default
true
prerender?โ
boolean | readonly string[]
Render this route to static HTML at build time. Useful for SEO and AI crawlers. The page then hydrates on the client for full interactivity.
Accepts either:
trueโ prerender this route's own path. The path must be fully static (no:paramName,*, or?segments).- an array of concrete paths to prerender. Use this to prerender specific
instances of a dynamic route (e.g.
["/blog/intro", "/blog/changelog"]for a"/blog/:slug"route). Every listed path must be fully static and must match this route's path pattern.
In either case the route's page cannot have Page.authRequired set, since prerendered content can't depend on the logged-in user. See Prerendering.
Default
false
Example
import { app, page, route } from "@wasp.sh/spec"
import { LandingPage } from "./src/LandingPage" with { type: "ref" }
import { BlogPostPage } from "./src/BlogPostPage" with { type: "ref" }
export default app({
// ...
spec: [
route("LandingRoute", "/", page(LandingPage), {
prerender: true,
}),
route("BlogPostRoute", "/blog/:slug", page(BlogPostPage), {
prerender: ["/blog/intro", "/blog/changelog"],
}),
],
})
Returnsโ
Exampleโ
import { page, route } from '@wasp.sh/spec'
import MainPage from './src/MainPage' with { type: 'ref' }
route('MainRoute', '/', page(MainPage))