Skip to content

Conversation

prave01
Copy link

@prave01 prave01 commented Sep 1, 2025

Fix(typedRoutes): respect trailingSlash config in generated routes - Issue #83185

Mandatory checks :

✅ Tests added and verified (/test/e2e/typed-routes-trailing-slash/typed-routes-trailing-slash.test.ts)
✅ Checked with locally build and exported Tarball version
✅ Works for both app and pages router

About the issue

  • The issue is, after enabling trailingSlash=true and typedRoutes=true in nextjs.config, he could't able to find the snippets for generated routes types with trailing slash behind.

How i solved it

  • Originally, generateLinkTypesFile only received the routesManifest, so it always wrote routes without considering trailingSlash.
  • I updated the function signature to also accept the full NextConfigComplete object.

Changes made

  • Passed config into generateLinkTypesFile:
/packages/next/src/server/lib/router-utils/route-types-utils.ts

await fs.promises.writeFile(
  linkTypesPath,
  generateLinkTypesFile(manifest, config)
)
  • Updated function signature:
/packages/next/src/server/lib/router-utils/typegen.ts

export function generateLinkTypesFile(
  routesManifest: RouteTypesManifest,
  config: NextConfigComplete
): string
  • Modified route serialization logic to respect trailingSlash:
/packages/next/src/server/lib/router-utils/typegen.ts

staticRouteTypes.push(
  config.trailingSlash && route !== '/' ? `${routeType}/` : routeType
)

About Test

  • ✅ Sets up a headless Next.js app with trailingSlash: true and typedRoutes: true.
  • ✅ Checks the generated link.d.ts file includes / and /dashboard/ as static routes.
  • ✅ Confirms that no dynamic routes are generated (DynamicRoutes = never).
  • ✅ Launches in headless and navigates to /dashboard/ via a typed <Link>.
  • ✅ Verifies the URL has the trailing slash (/dashboard/).
  • ✅ Asserts that the page renders correctly with <h1>Dashboard</h1>.

Why this test matters

  • Prevents regressions: ensures trailingSlash + typedRoutes always behave consistently.
  • Covers both build-time types and runtime navigation.

Reference - #23988

Closes NEXT-
Fixes #83185

prave01 and others added 2 commits September 2, 2025 12:48
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypedRoutes doesn't work with trailingSlash config
2 participants