Skip to content

[bug] Prefixing dynamic path segments on redirects breaks typedRoutes, generating static routes instead of dynamic routes #86877

@davbrito

Description

@davbrito

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/next-issue-dynamic-path-redirect-types-4kxlpc

To Reproduce

  1. Add the following redirects in your next.config.js:
typedRoutes: true, // ensure typed routes enabled
redirects() {
  return [
    {
      source: "/c:id",
      destination: "/dashboard/customers/:id",
      permanent: true,
    },
    {
      source: "/p:id",
      destination: "/dashboard/products/:id",
      permanent: true,
    },
  ];
},
  1. Run next typegen and notice the produced route lists:
Image
  1. Observe that routes prefixed with a dynamic path segment (e.g., /a/m:id, /a/p:id) are generated as static routes instead of dynamic routes in the type generation result.

Current vs. Expected behavior

Current behavior:

  • When dynamic path segments are prefixed in redirect source paths (such as "/a/m:id"), typedRoutes generates these as static routes (e.g., "/a/m[id]") rather than dynamic routes with appropriate parameter typing.

Expected behavior:

  • Dynamic segments in redirect sources should cause typedRoutes to generate those paths as dynamic routes with params.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.12.1
  npm: 10.5.0
  Yarn: N/A
  pnpm: 10.24.0
Relevant Packages:
  next: 16.0.7 // Latest available version is detected (16.0.7).
  eslint-config-next: N/A
  react: 19.2.1
  react-dom: 19.2.1
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Dynamic Routes, Redirects

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dynamic RoutesRelated to dynamic routes.RedirectsRelated to redirecting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions