Every place that holds a route path is typed against the real routes, so a rename breaks the build, not a link.

The problem

Route paths get copied everywhere as plain strings: nav configs, tab maps, link helpers. Then someone renames a route, and half of those strings quietly point at nothing until a person clicks one.

A typed <Link> component helps, but only at the JSX boundary. Nav arrays, lookup maps and utility functions hold paths long before they reach a link, if they ever do, and nothing checks them there.

What I concluded

One type: a union of every real route path. Everything that holds a path is typed against it.

Where the union comes from

If your router generates types, it’s one line. A file-based router’s code generator already knows every route, so the alias just points at it, and running the generator keeps it current.

If your router doesn’t, keep every route in one as const map. The union is the map’s values, and template literal types can pull the params out of each path, so a link helper knows /orders/:orderId needs an orderId.

export const ROUTES = {
  orders: "/orders",
  order: "/orders/:orderId",
  orderReturns: "/orders/:orderId/returns",
} as const;

export type RoutePath = (typeof ROUTES)[keyof typeof ROUTES];

to("order", { orderId: "123" });   // "/orders/123"
to("order", {});                   // ✗ missing orderId
to("ordr", { orderId: "1" });      // ✗ no such route

Use it wherever a path lives

type NavItem = { label: string; path: RoutePath };
const TABS: Record<string, RoutePath> = { /* ... */ };
function buildLink(to: RoutePath, params: Params) { /* ... */ }

Rename /customers/accounts/:id to /customers/:id and every nav item, tab map and link helper still using the old string fails the type check.

Rules

  • One source of route paths. Generated by the router, or one map. Never a second list.
  • Type every holder, not just links: nav configs, tab maps, helpers.
  • Params come from the path. A helper can’t build a link without them.
  • External links are string on purpose, with a comment saying why.

What you get

Renaming or deleting a route turns every stale reference into a compile error. Typed links cover the JSX, the path union covers everything else, and together nothing points at a route that isn’t there.

Related: Access control, URL state.