mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #239] Wire up RouterContext.Provider in Pages Router so next/compat/router returns a real router #60
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#60
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?
Originally created by @southpolesteve on GitHub (Mar 3, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/239
Context
PR #224 added a
next/compat/routershim that mirrors Next.js's implementation:useContext(RouterContext). This works correctly for App Router apps (returnsnull, which is the expected behavior for libraries like@clerk/nextjs).Problem
In real Next.js, the Pages Router wraps the app in a
<RouterContext.Provider>with the actual router instance. This meansnext/compat/router'suseRouter()returns the real router in Pages Router pages, andnullin App Router pages.Vinext's
next/routershim reads fromwindow.locationdirectly and never renders aRouterContext.Provider. This meansnext/compat/routerreturnsnullalways, even in Pages Router apps.Expected behavior
useRouter()fromnext/compat/routerreturnsnull(correct today)useRouter()fromnext/compat/routerreturns theNextRouterinstance (broken today, always returnsnull)Fix
Render
<RouterContext.Provider value={router}>in the Pages Router rendering path (likely inserver/dev-server.tsandserver/prod-server.ts) so thatuseContext(RouterContext)returns the actual router when the Pages Router is mounted.