-
Notifications
You must be signed in to change notification settings - Fork 30k
Open
Labels
Dynamic RoutesRelated to dynamic routes.Related to dynamic routes.RedirectsRelated to redirecting.Related to redirecting.
Description
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/next-issue-dynamic-path-redirect-types-4kxlpc
To Reproduce
- 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,
},
];
},- Run
next typegenand notice the produced route lists:
- 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/AWhich 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
Labels
Dynamic RoutesRelated to dynamic routes.Related to dynamic routes.RedirectsRelated to redirecting.Related to redirecting.