anomalyco/sst · error

In "${name}" Router, the route path "${path}" must start wit

Error message

In "${name}" Router, the route path "${path}" must start with a "/"

What it means

Router inline route keys are CloudFront cache-behavior path patterns and must be absolute paths beginning with "/". normalizeRoutes validates each key and throws if a path does not start with a slash.

Source

Thrown at platform/src/components/aws/router.ts:1747

        return protection;
      });
    }

    function handleInlineRoutes() {
      let defaultCachePolicy: cloudfront.CachePolicy;
      let defaultCfFunction: cloudfront.Function;
      let defaultOac: OriginAccessControl;
      const routes = normalizeRoutes();
      const cdn = createCdn();
      return cdn;

      function normalizeRoutes() {
        return output(args.routes!).apply((routes) => {
          const normalizedRoutes = Object.fromEntries(
            Object.entries(routes).map(([path, route]) => {
              // Route path must start with "/"
              if (!path.startsWith("/"))
                throw new Error(
                  `In "${name}" Router, the route path "${path}" must start with a "/"`,
                );

              route = typeof route === "string" ? { url: route } : route;

              const hasUrl = "url" in route ? 1 : 0;
              const hasBucket = "bucket" in route ? 1 : 0;
              if (hasUrl + hasBucket !== 1)
                throw new Error(
                  `In "${name}" Router, the route path "${path}" can only have one of url or bucket`,
                );

              return [path, route];
            }),
          );

          normalizedRoutes["/*"] = normalizedRoutes["/*"] ?? {
            url: "https://do-not-exist.sst.dev",

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Prefix every route key with "/" (e.g. "*" -> "/*", "api/*" -> "/api/*")
  2. Validate route keys come from a map you control rather than user/external input

Example fix

// before
routes: { "*": "https://example.com" }
// after
routes: { "/*": "https://example.com" }
Defensive patterns

Strategy: validation

Validate before calling

const routes = { "*": "https://example.com" };
for (const path of Object.keys(routes)) {
  if (!path.startsWith("/"))
    throw new Error(`Route path "${path}" must start with "/"`);
}

Type guard

function isValidRoutePath(p: string): p is `/${string}` {
  return p.startsWith("/");
}

Try / catch

try {
  const r = new Router(ctx, "R", { routes });
} catch (e) {
  if (String(e).includes('must start with a "/"')) console.error("Fix route keys");
  throw e;
}

Prevention

When it happens

Trigger: `new Router(..., { routes: { "*": ..., "api/*": ... } })` — any route key missing the leading "/".

Common situations: Copy-pasting express-style route patterns ("*", "api/*", "home") into the Router routes map.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/04fa2ed2198ddcdf. Report an issue: GitHub.