Routing

Routing

Static, dynamic, and catch-all routes with nested layouts.

Updated: 2026-07-26

Route patterns

A file in pages/ becomes a route. Bracket syntax adds parameters. More specific routes win over less specific ones regardless of file order.

  • index.tsx -> /
  • about.tsx -> /about
  • [slug].tsx -> /:slug
  • [...all].tsx -> /* (catch-all, params.wild)
  • layout.tsx -> nested layout boundary for the directory
  • 404.tsx -> not-found entity
  • error.tsx -> error entity

Route parameters

Parameters arrive on ctx.params, already URL-decoded. Query strings are on ctx.searchParams as a standard URLSearchParams.

src/pages/docs/[slug].tsx
import type { SiteRouteContext } from '@rigbyhost/karui/ssr';

export default function Doc(ctx: SiteRouteContext) {
  const tab = ctx.searchParams.get('tab') ?? 'overview';
  return <h1>{ctx.params.slug} โ€” {tab}</h1>;
}

Redirects

Call redirect() from a loader or an action. On the server it becomes a Location header; on the client it becomes a navigation.

tsx
import { redirect } from '@rigbyhost/karui/router';

export function loader(ctx) {
  if (!ctx.state.user) redirect('/login');
  return getDashboard();
}