fix(router-generator): remove trailing slash from pathless route group paths #5491
main fromrefs/pull/5491/head·merged by schiller-manuel(GitHub profile, opens in a new tab) when a route group is defined, the generator strips the group from the path but keeps the "/" preceding this group in the path resulting in these paths being treated as routes by the generator.
For example /abc/(group) is resolved to /abc/ instead of /abc. This results in a few issues. One being that when both route and index are defined in a group, the route is determined to have a higher rank when sorting the routes and hence is matched prior to the index.
This PR resolves this issue by checking if the route is a layout (both pathless and non-pathless) and if so removes any trailing slash that remains after the group has been split.
Due to this error paths like /(group)/_layout resulted in /(group) to be defined as a virtual route to load _layout in this virtual parent route. With this fix the _layout route is correctly loaded with the rootRoute being its parent. Due to this, the generated route trees for basic-file-based e2e tests and the snapshots for the route-group unit tests in router-generator had to be updated as well.
This PR also adds a test to the path-above-route-in-group to test for the index path being correctly handled when used together with a route path in the same group.
This resolves #5486
Summary by CodeRabbit#
- New Features
- Group routes are now exposed directly under the root, simplifying navigation and type mappings.
- Added support for index routes within grouped paths, improving addressability of “path above route in group” scenarios.
- Bug Fixes
- Normalized trailing slashes for layout and pathless layout routes to prevent duplicate or inconsistent paths.
- Tests
- Updated e2e and snapshot tests to reflect the new routing structure and type surfaces.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-generator
View your CI Pipeline Execution ↗ for commit 8835eac687517df79df157b95e9e988fa9ae53fd
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 5m 24s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 30s View ↗
☁️ Nx Cloud last updated this comment at
2025-10-15 23:03:18UTCMore templates
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5491@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5491@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5491@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5491@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5491@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5491@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5491@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5491@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5491@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5491@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5491@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5491@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5491@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5491@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5491@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5491@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5491@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5491@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5491@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5491@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5491@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5491@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5491@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5491@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5491@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5491@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5491@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5491@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5491@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5491@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5491@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5491@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5491@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5491commit:
8835eacHey! Thanks for the quick PR. Do you think this can fix #5498 too ?
Sign in to join this conversation.
Walkthrough#
Refactors generated route trees to expose group-related routes directly under the root, removes intermediate group route nodes, adds trailing-slash normalization for layout routes in the generator, and introduces an index route for a path-above-route-in-group scenario. Updates associated snapshots for React and Solid e2e and generator tests.
Changes#
e2e/react-router/basic-file-based/src/routeTree.gen.tsrootRouteImport; removegroupRoute/groupRouteWithChildren; update FileRoutesBy* mappings so'/'maps toIndexRoute; addgroupLayoutRoute,groupInsideRoute,groupLazyinsideRoute,groupSubfolderInsideRoute.e2e/solid-router/basic-file-based/src/routeTree.gen.ts/(group)entries; update FileRoutesBy* typings;'/'maps toIndexRoute.packages/router-generator/src/generator.tsremoveTrailingSlashusage forlayoutandpathless_layoutnodes to normalizecleanedPath; import utility; adjust path cleaning in two spots.packages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.ts.../_layout-*); reparent to root; update FileRoutesBy* unions; apply._addFileTypes<FileRouteTypes>()in route tree construction.packages/router-generator/tests/generator/path-above-route-in-group/routeTree.snapshot.ts/a/$b/to/a/$b; addABcIndexRouteunderABcRouteRoute; update FileRoutesBy* and children typings to include index route.packages/router-generator/tests/generator/path-above-route-in-group/routes/a/$b/(c)/index.tsxindex.tsximplementingRoutefor'/a/$b/(c)/'that renders an index component.packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts/(bar)entry, introduce/(bar)/_barunder root; adjust another-group layout paths; update FileRoutesBy* andRootRouteChildren(e.g.,barBarRoute).Sequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~60 minutes
Suggested labels#
package: react-router,package: solid-routerSuggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
. _addFileTypes<FileRouteTypes>()extension and a broad restructuring of route-groups tests that go beyond just removing trailing slashes. These modifications fall outside the scope of fixing pathless route group slash normalization and correcting index rendering. Including them here risks obscuring the targeted fix and conflating unrelated changes.✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 4303a8a716c7f3d7ca292a6793b0cc4896394b8b and 8835eac687517df79df157b95e9e988fa9ae53fd.
📒 Files selected for processing (7)
e2e/react-router/basic-file-based/src/routeTree.gen.ts(8 hunks)e2e/solid-router/basic-file-based/src/routeTree.gen.ts(8 hunks)packages/router-generator/src/generator.ts(2 hunks)packages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.ts(5 hunks)packages/router-generator/tests/generator/path-above-route-in-group/routeTree.snapshot.ts(4 hunks)packages/router-generator/tests/generator/path-above-route-in-group/routes/a/$b/(c)/index.tsx(1 hunks)packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts(8 hunks)🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/router-generator/src/generator.tspackages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.tse2e/solid-router/basic-file-based/src/routeTree.gen.tspackages/router-generator/tests/generator/route-groups/routeTree.snapshot.tse2e/react-router/basic-file-based/src/routeTree.gen.tspackages/router-generator/tests/generator/path-above-route-in-group/routes/a/$b/(c)/index.tsxpackages/router-generator/tests/generator/path-above-route-in-group/routeTree.snapshot.tspackages/{router-cli,router-generator,router-plugin,virtual-file-routes}/**
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/router-generator/src/generator.tspackages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.tspackages/router-generator/tests/generator/route-groups/routeTree.snapshot.tspackages/router-generator/tests/generator/path-above-route-in-group/routes/a/$b/(c)/index.tsxpackages/router-generator/tests/generator/path-above-route-in-group/routeTree.snapshot.tse2e/**
📄 CodeRabbit inference engine (AGENTS.md)
Files:
e2e/solid-router/basic-file-based/src/routeTree.gen.tse2e/react-router/basic-file-based/src/routeTree.gen.ts🧠 Learnings (1)
📚 Learning: 2025-10-08T08:11:47.088Z
Applied to files:
packages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.tspackages/router-generator/tests/generator/route-groups/routeTree.snapshot.tspackages/router-generator/tests/generator/path-above-route-in-group/routeTree.snapshot.ts🧬 Code graph analysis (4)
packages/router-generator/src/generator.ts (3)
e2e/solid-router/basic-file-based/src/routeTree.gen.ts (1)
e2e/react-router/basic-file-based/src/routeTree.gen.ts (1)
packages/router-generator/tests/generator/path-above-route-in-group/routeTree.snapshot.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (22)
Comment `@coderabbitai help` to get the list of available commands and usage tips.