-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(router-generator): remove trailing slash from pathless route group paths #5491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughRefactors 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
Sequence Diagram(s)sequenceDiagram
autonumber
participant FS as File system routes
participant Gen as Router Generator
participant Utils as removeTrailingSlash
participant RT as Generated Route Tree
FS->>Gen: Provide nodes (including group and layout nodes)
Note over Gen: Handle node paths and types
Gen->>Gen: Compute cleanedPath
alt node._fsRouteType in {layout, pathless_layout}
Gen->>Utils: removeTrailingSlash(cleanedPath)
Utils-->>Gen: cleanedPath (no trailing slash)
end
Gen->>Gen: Assign parentRoute = root for group-derived routes
Gen->>RT: Emit routes under root (groupLayout/inside/lazyinside/subfolder)
Note over RT: Index routes attached where path-above-group needs index
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
🧰 Additional context used📓 Path-based instructions (3)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/{router-cli,router-generator,router-plugin,virtual-file-routes}/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
e2e/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2025-10-08T08:11:47.088Z
Applied to files:
🧬 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 |
View your CI Pipeline Execution ↗ for commit 8835eac
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/nitro-v2-vite-plugin
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-static-server-functions
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
Hey! Thanks for the quick PR. Do you think this can fix #5498 too ? |
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