Repository navigation
Conversation
The ~ prefix is meant to escape from nested route bases and navigate to absolute paths within the app. Before this fix, ~/path would ignore all bases including the explicit Router base prop, navigating to /path on the domain root. After this fix, ~/path respects the outermost explicit Router base. With <Router base="/app">, ~/schedule navigates to /app/schedule instead of /schedule, matching the expected behavior where ~ means "absolute within the app" rather than "absolute on the domain". Implementation: - Add explicitBase property to router context that tracks only the outermost explicit Router base prop (not nested route bases) - Mark Routers created by nested Routes with internal _nested flag - Update absolutePath() and Link href generation to use explicitBase for ~ paths instead of ignoring the base entirely Tests updated to reflect new behavior and verify the fix for the reported issue scenario. Co-authored-by: Alexey Taktarov <molefrog@users.noreply.github.com>
|
|
size-limit report 馃摝
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a Router has a
baseprop and you use~prefix for absolute-within-app paths, the navigation ignores the Router base and navigates outside the expected scope.For example, with
<Router base="/app">, a link<Link href="~/schedule">would navigate to/scheduleinstead of the expected/app/schedule.The
~prefix is documented as an escape hatch to navigate to absolute paths when using nested routes, but the implementation was treating it as "absolute on the domain" rather than "absolute within the app".Solution
This fix makes
~paths respect the outermost explicit Routerbaseprop while still escaping from nested route bases (created by<Route nest>).The implementation:
explicitBaseproperty to the router context that tracks only the outermost explicit Router base<Route nest>inheritexplicitBasewithout modifying it~paths, the router usesexplicitBaseinstead of ignoring all basesBehavior
Before: With
<Router base="/app">,~/schedulenavigates to/scheduleAfter: With
<Router base="/app">,~/schedulenavigates to/app/scheduleThis matches the expected semantics where
~means "absolute within the app" rather than "absolute on the domain".Testing
base聽#558Fixes #558