-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
fix(router-generator): generator should not infer trailing slash is not necessary for index routes #1597
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 2e0605e. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
@@ -123,15 +123,15 @@ declare module '@tanstack/react-router' { | |||
} | |||
'/blog/$slug/': { | |||
id: '/blog/$slug/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if the id should have a trailing slash or not? But at least this fixes the fullPath
and path
. TS used to normalize this but its right to move this work to the generator as we don't want the compiler spending time on stuff the generator can do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this id
field meant to be used in Router?
If it is being used in places like useSearch, and hooks that use from
, then trailing-slashes should be removed (with the exception to index routes).
For example, in the basic example, from
accepts the following options regardless of the trailingSlash
setting.
/
/posts
/posts/
/posts/$postId
__root__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me clarify. These are index routes that I'm removing trailing slashes from. It's index routes without a route.tsx
which was causing the problem. Before I guess TS was removing this slash, then I moved it to the generator and fullPath
got a trailing slash in this situation.
So do you think id
should have a trailing slash or not in this situation? Because TFilePath
does have one and I guess always had one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked previous versions and id
always had a trailing slash in this situation. I'm going to merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a test for different trailingSlash
settings too?
We have loads at the type level. The problem was the types expect https://github.com/TanStack/router/blob/main/packages/react-router/tests/link.test-d.tsx I think the generator tests should cover that the generated types are correct |
@@ -123,15 +123,15 @@ declare module '@tanstack/react-router' { | |||
} | |||
'/blog/$slug/': { | |||
id: '/blog/$slug/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this id
field meant to be used in Router?
If it is being used in places like useSearch, and hooks that use from
, then trailing-slashes should be removed (with the exception to index routes).
For example, in the basic example, from
accepts the following options regardless of the trailingSlash
setting.
/
/posts
/posts/
/posts/$postId
__root__
Trailing slashes should only be there if the index route has to be uniquely identified by it.
fixes #1596