Repository navigation
[Pages] fix: interpolate query-only navigation when asPath has a query string - #101198
Open
Alvi-Rahman wants to merge 2 commits into
Open
Alvi-Rahman wants to merge 2 commits into
Alvi-Rahman wants to merge 2 commits into
Conversation
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.
Fixes #84942
What?
In the Pages Router, a query-only
router.push({ query })or<Link href="?…">on a route with a dynamic segment followed by a static one (e.g./[id]/detail) keeps the old segment when the current URL already has a query string.This is a regression from 15.5.0, introduced by #82236.
Why?
resolveHref(packages/next/src/client/resolve-href.ts) decides whether the current page was rewritten by running the anchored route regex againstrouter.asPath.asPathincludes the query string, so^/([^/]+?)/detail(?:/)?$never matches/b/detail?fromId=a. The page is then treated as rewritten, and the query is never interpolated into the path.Routes like
/[id]only appeared to work because the segment pattern happened to swallow the query string.How?
Match the regex against the pathname only, using the existing
parsePathhelper.Tests
Added a
dynamic-mid-path/[id]/detailpage and two cases (router.pushandLink) to thetest/e2e/use-router-with-rewritessuite from #82236.Both new cases fail on canary (expected
b/c, gota). All 11 tests in the suite pass with the fix in Turbopack dev, webpack dev, and production builds with both bundlers.