-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(router-core): ensure rewrite basepath applies consistently #5202
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
Open
leesb971204
wants to merge
9
commits into
TanStack:main
Choose a base branch
from
leesb971204:fix/buildlocation-href-rewrite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−19
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
23be5f9
fix(router-core): ensure href proterty uses rewritten URL in buildLoc…
leesb971204 593cb78
fix(router-core): rewrite examples in RouterOptions for improved clarity
leesb971204 508303a
Merge remote-tracking branch 'upstream/main' into fix/buildlocation-h…
leesb971204 2b831cf
test(react-router): add tests for browser url includes basepath on ro…
leesb971204 a9dbeb7
Merge remote-tracking branch 'upstream/main' into fix/buildlocation-h…
leesb971204 b9a4ce3
Merge remote-tracking branch 'upstream/main' into fix/buildlocation-h…
leesb971204 e900a66
Merge branch 'main' into fix/buildlocation-href-rewrite
leesb971204 a161948
fix(router): use publicHref for URL comparisons in Transitioner and r…
leesb971204 977587d
trigger CI
leesb971204 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,12 +290,15 @@ export interface RouterOptions< | |
* ```ts | ||
* const router = createRouter({ | ||
* routeTree, | ||
* rewrite: rewriteBasepath('/basepath') | ||
* // Or wrap existing rewrite functionality | ||
* rewrite: rewriteBasepath('/basepath', { | ||
* output: ({ url }) => {...}, | ||
* input: ({ url }) => {...}, | ||
* }) | ||
* rewrite: rewriteBasepath({ basepath: '/basepath' }) | ||
* // Or compose with existing rewrite functionality | ||
* rewrite: composeRewrites([ | ||
* rewriteBasepath({ basepath: '/basepath', caseSensitive: true }), | ||
* { | ||
* input: ({ url }) => {...}, | ||
* output: ({ url }) => {...}, | ||
* } | ||
* ]) | ||
* }) | ||
* ``` | ||
* @default '/' | ||
|
@@ -1688,7 +1691,7 @@ export class RouterCore< | |
return { | ||
publicHref: | ||
rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash, | ||
href: fullPath, | ||
href: rewrittenUrl.href.replace(rewrittenUrl.origin, ''), | ||
url: rewrittenUrl.href, | ||
pathname: nextPathname, | ||
search: nextSearch, | ||
|
@@ -1784,8 +1787,11 @@ export class RouterCore< | |
return isEqual | ||
} | ||
|
||
const latestPublicHref = this.latestLocation.publicHref ?? this.latestLocation.href | ||
const nextPublicHref = next.publicHref ?? next.href | ||
|
||
const isSameUrl = | ||
trimPathRight(this.latestLocation.href) === trimPathRight(next.href) | ||
trimPathRight(latestPublicHref) === trimPathRight(nextPublicHref) | ||
Comment on lines
+1790
to
+1794
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. compare publicHref so basePath rewrites don't mask real URL changes |
||
|
||
const previousCommitPromise = this.commitLocationPromise | ||
this.commitLocationPromise = createControlledPromise<void>(() => { | ||
|
@@ -1942,11 +1948,14 @@ export class RouterCore< | |
} | ||
} | ||
|
||
const latestPublicHref = this.latestLocation.publicHref | ||
const nextPublicHref = nextLocation.publicHref | ||
|
||
if ( | ||
trimPath(normalizeUrl(this.latestLocation.href)) !== | ||
trimPath(normalizeUrl(nextLocation.href)) | ||
trimPath(normalizeUrl(latestPublicHref)) !== | ||
trimPath(normalizeUrl(nextPublicHref)) | ||
) { | ||
throw redirect({ href: nextLocation.href }) | ||
throw redirect({ href: nextPublicHref }) | ||
Comment on lines
+1951
to
+1958
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ensure URL with basePath matches what we'd build(for tanstack start) |
||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.
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.
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.
publicHref carries rewrite/basePath changes that should reflect in the browser URL