Skip to main content
Version: 0.24

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 (see Prerendering) and 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โ€‹

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

If true, Wasp renders this page to static HTML at build time. Useful for SEO and AI crawlers.

Only works on fully static paths (no :paramName, *, or ? segments) and cannot be combined with Page.authRequired. See Prerendering.

Default

false

Example

import { app, page, route } from "@wasp.sh/spec"
import { SomePage } from "./src/SomePage" with { type: "ref" }

export default app({
// ...
spec: [
route("NameRoute", "/some-path", page(SomePage), {
prerender: true,
}),
],
})

Returnsโ€‹

Route

Exampleโ€‹

import { page, route } from '@wasp.sh/spec'
import MainPage from './src/MainPage' with { type: 'ref' }

route('MainRoute', '/', page(MainPage))