mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #483] [MERGED] fix: Link onNavigate URL resolution for relative hrefs #605
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#605
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/483
Author: @JaredStowell
Created: 3/12/2026
Status: ✅ Merged
Merged: 3/12/2026
Merged by: @james-elicx
Base:
main← Head:jstowell/fix-link-onnavigate-relative-hrefs📝 Commits (4)
74994f9Fix onNavigate relative href reportd05dcd8Verify onNavigate relative href786d92aFix onNavigate URL mismatch18e75b0Review url-utils changes📊 Changes
12 files changed (+389 additions, -95 deletions)
View changed files
📝
packages/vinext/src/shims/link.tsx(+21 -48)📝
packages/vinext/src/shims/navigation.ts(+4 -10)📝
packages/vinext/src/shims/router.ts(+17 -35)📝
packages/vinext/src/shims/url-utils.ts(+93 -0)📝
tests/e2e/app-router/nextjs-compat/navigation.spec.ts(+24 -0)📝
tests/e2e/pages-router/link-advanced.spec.ts(+22 -0)📝
tests/fixtures/app-basic/app/nextjs-compat/nav-link-test/page.tsx(+2 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/nav-link-test/relative-query-link.tsx(+34 -0)📝
tests/fixtures/app-basic/next-shims.d.ts(+1 -0)📝
tests/fixtures/pages-basic/next-shims.d.ts(+1 -0)📝
tests/fixtures/pages-basic/pages/link-test.tsx(+14 -0)📝
tests/link.test.ts(+156 -2)📄 Description
Fix
next/linkonNavigateso its callback URL matches the actual navigation target for relative hrefs.This aligns
Linkcallback behavior with the browser/history destination for cases like?page=2,#hash, and other relative targets, including whenbasePathis configured.What changed
onNavigate.urlin thenext/linkshim to use the same resolved target as navigationbasePathbrowser URL resolution in shared URL helpersbasePathprefixes are not applied twicehrefbehavior underbasePathfor relative valuesnext/navigationandnext/routerto use the same shared browser-target resolution pathonNavigatetypings aligned with Next.js and use local casts where vinext exposesevent.urlTests
Added and updated regression coverage for:
basePath+ locale-prefixed browser targetsbasePathbasePathLink onNavigaterelative query navigationLink onNavigaterelative query navigationVerification
Ran targeted checks:
pnpm test tests/link.test.tsPLAYWRIGHT_PROJECT=pages-router pnpm exec playwright test tests/e2e/pages-router/link-advanced.spec.ts -g "onNavigate reports the resolved URL for relative query hrefs"PLAYWRIGHT_PROJECT=app-router pnpm exec playwright test tests/e2e/app-router/nextjs-compat/navigation.spec.ts -g "Link onNavigate reports the resolved URL for relative query hrefs"pnpm run typecheckpnpm run fmt🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.