-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
fix: properly support index routes with a path in useResolvedPath #9486
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
🦋 Changeset detectedLatest commit: ce47c0a The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| parsePath, | ||
| resolveTo, | ||
| warning, | ||
| UNSAFE_getPathContributingMatches as getPathContributingMatches, |
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.
Removed the duped function and exported it as a private function from @remix-run/router
packages/router/utils.ts
Outdated
| index === 0 || | ||
| (!match.route.index && | ||
| match.pathnameBase !== matches[index - 1].pathnameBase) | ||
| index === 0 || match.pathnameBase !== matches[index - 1].pathnameBase |
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.
Don't look for match.route.index at all - just look to see if the pathnameBase changed
| index === 0 || | ||
| (!match.route.index && | ||
| match.pathnameBase !== matches[index - 1].pathnameBase) | ||
| index === 0 || (match.route.path && match.route.path.length > 0) |
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.
2 issues fixed here:
- Looking at
route.indexdoesn't work since index routes can have paths - Using
pathnameBasedoesn't work for nested splat routes since they don't add topathnameBase, so instead we just look for the route do define a non-emptypathvalue (also this means this becomes a function that we can use directly in remix since remix doesn't exposepathnameBaseon matches)
While not a super common pattern, this was causing
FormanduseSubmitto use incorrect default actions when used in an index route with a path (more commonly generated from remix conventional routes):A call to
useFormActioninsideCompwould incorrectly trim thefooroute ingetPathContributingMatchesbecause it was anindexroute, and then it would generate a form action of/?indexinstead of/foo?index