Basker Docs

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:

ResultWhenWhat to do
RouteMatchA published record has this path.Render node. Choose the layout from node.__typename or node.contentType, and from node.template.
RouteRedirectAn 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.
RouteNotFoundNothing 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 from EventInstance.path.
  • A smart collection has a path such as /collections/featured-concerts. The match returns a SmartCollection node.
  • For another language, pass the path with its prefix, such as /es/visit, and set locale=es on 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 example routes(types: [PAGE, EVENT]).
  • routes leaves out event instances and smart collections unless you ask for them with types, for example types: [EVENT_INSTANCE, SMART_COLLECTION].
  • routes leaves out the 404 page.
  • routes returns 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 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.

On this page