{"record":{"id":"4d3b6ec404fa2d10","repo":"anomalyco/sst","slug":"cannot-use-both-routes-and-route-function-t","errorCode":null,"errorMessage":"Cannot use both `routes` and `.route()` function to add routes.","messagePattern":"Cannot use both `routes` and `\\.route\\(\\)` function to add routes\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/router.ts","lineNumber":2543,"sourceCode":"   *   rewrite: {\n   *     regex: \"^/api/(.*)$\",\n   *     to: \"/$1\"\n   *   }\n   * });\n   * ```\n   *\n   * Here something like `/api/users/profile` will be routed to\n   * `https://api.example.com/users/profile`.\n   */\n  public route(\n    pattern: Input<string>,\n    url: Input<string>,\n    args?: Input<RouterUrlRouteArgs>,\n  ) {\n    all([pattern, args, this.hasInlineRoutes]).apply(\n      ([pattern, args, hasInlineRoutes]) => {\n        if (hasInlineRoutes)\n          throw new VisibleError(\n            \"Cannot use both `routes` and `.route()` function to add routes.\",\n          );\n\n        new RouterUrlRoute(\n          `${this.constructorName}Route${pattern}`,\n          {\n            store: this.kvStoreArn!,\n            routerNamespace: this.kvNamespace!,\n            pattern,\n            url,\n            routeArgs: args,\n          },\n          { provider: this.constructorOpts.provider },\n        );\n      },\n    );\n  }\n","sourceCodeStart":2525,"sourceCodeEnd":2561,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/router.ts#L2525-L2561","documentation":"A Router cannot mix the inline `routes` prop with the lazy `.route()` method. The `route()` method checks `hasInlineRoutes` and throws this VisibleError if inline routes were provided in the constructor.","triggerScenarios":"`new Router(..., { routes: {...} })` followed by a call to `router.route(pattern, url)`.","commonSituations":"Incrementally migrating an inline-routes Router to the lazy API while leaving old routes in place; adding one extra route to an existing inline-routes config.","solutions":["Move all routes to `.route()` calls and remove the `routes` prop from the constructor","Or keep everything inline and drop the `.route()` call"],"exampleFix":"// before\nconst r = new Router($app, \"R\", { routes: { \"/a/*\": \"https://a.com\" } });\nr.route(\"/b/*\", \"https://b.com\");\n// after\nconst r = new Router($app, \"R\", {});\nr.route(\"/a/*\", \"https://a.com\");\nr.route(\"/b/*\", \"https://b.com\");","handlingStrategy":"validation","validationCode":"if (routerArgs.routes && needsRouteFn)\n  throw new Error(\"Cannot mix `routes` prop with .route() calls\");","typeGuard":null,"tryCatchPattern":"try {\n  const r = new Router(ctx, \"R\", { routes });\n  r.route(\"/b/*\", \"https://b.com\");\n} catch (e) {\n  if (String(e).includes(\".route() function\")) console.error(\"Pick one route API\");\n  throw e;\n}","preventionTips":["Standardize on the lazy .route()/.routeBucket() API for all new Routers","Migrate inline routes fully (remove the prop) before adding routes programmatically","Encapsulate Router creation in one helper to enforce a single API"],"tags":["router","api-misuse","config-validation","sst"],"backgroundTag":"incompatible-component-options","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}