Routing
Resolve a URL to a record, a redirect, or the 404 page, and list every public URL for static builds
Use route(path:) to turn any URL on your site into content. It applies the same rules as a site that Basker renders: the redirects that editors set, then the record at that path, then the 404 page.
query Route($path: String!) {
route(path: $path) {
__typename
... on RouteMatch {
path
node {
__typename
contentType
id
title
template
}
}
... on RouteRedirect {
to
status
}
... on RouteNotFound {
page {
title
path
}
}
}
}With the variables {"path": "/events/holst-the-planets"}:
{
"data": {
"route": {
"__typename": "RouteMatch",
"path": "/events/holst-the-planets",
"node": {
"__typename": "Event",
"contentType": "EVENT",
"id": "6afccdd9f389348df01db29f",
"title": "Holst: The Planets",
"template": null
}
}
}
}Route results
route returns the RouteResult union. Select __typename and handle each member:
| Result | When | What to do |
|---|---|---|
RouteMatch | A published record has this path. | Render node. Choose the layout from node.__typename or node.contentType, and from node.template. |
RouteRedirect | An editor redirect matches the path. | Redirect the visitor to to with the HTTP status in status: 301 or 302. to is a site path or an absolute URL. |
RouteNotFound | Nothing matches. | Return HTTP status 404. Render page, the 404 page of the site, when it is not null. |
node is a Content interface. Use inline fragments to select the fields of each content type:
query RouteNode($path: String!) {
route(path: $path) {
... on RouteMatch {
node {
__typename
title
... on Event {
startDate
venue { title path }
}
... on Page {
breadcrumbs { label path }
}
}
}
}
}How a path matches
- Pass the site-relative path, for example
/visit/parking. Basker ignores a query string and a fragment, removes a trailing slash, and joins repeated slashes. - Redirects match first, so a redirect from a live page wins over the page.
/is the home page.- A performance has a path such as
/events/instances/6hd63qjg/2027-01-07/holst-the-planets. Read it fromEventInstance.path. - A smart collection has a path such as
/collections/featured-concerts. The match returns aSmartCollectionnode. - For another language, pass the path with its prefix, such as
/es/visit, and setlocale=eson the request. See Languages.
List every public URL
routes lists the public URLs of the site in the language of the request. Use it to generate static pages and sitemaps.
{
routes(page: 1, limit: 100) {
totalDocs
hasNextPage
docs {
path
contentType
id
title
updatedAt
}
}
}- To list some content types only, pass
types, for exampleroutes(types: [PAGE, EVENT]). routesleaves out event instances and smart collections unless you ask for them withtypes, for exampletypes: [EVENT_INSTANCE, SMART_COLLECTION].routesleaves out the 404 page.routesreturns up to 10,000 records of each content type.- Each entry has
node, so you can select content fields in the same query. Keep the selection small. Large selections on many entries reach the work limit.
Copy redirects to your host
route applies redirects for you. For a static host that applies redirects itself, read the rules with redirects:
{
redirects(limit: 100) {
totalDocs
docs {
from
to
status
matchType
}
}
}matchType is exact, prefix, or contains. A prefix rule matches every path that starts with from. A contains rule matches a pattern in the path. Check that your host supports the rule before you copy it.
Navigation
navigation returns the site tree, top level first, in menu order. It leaves out pages that editors hid from navigation, unless you pass includeHidden: true.
{
navigation {
title
path
children {
title
path
}
}
}A page also has parent, children, and breadcrumbs.