fix(studio): expose router.route in next/router compat shim

Next's pages-router useRouter() returns both \`pathname\` and \`route\`
holding the bracketed route pattern (always the same value in pages
mode). Our compat shim only exposed \`pathname\`, so studio call sites
that read \`router.route\` (AppLayout/BranchLink, AppLayout/ProjectDropdown)
got \`undefined\` and crashed when sanitizeRoute() did \`route.split('/')\`.
Surfaced when opening the project selector dropdown — BranchLink
errored at render and tripped the route's ErrorBoundary.

Mirror \`pathname\` into \`route\` in both shims (next/router and
next/compat/router).
This commit is contained in:
Alaister Young committed 2026-05-08 15:19:46 +08:00
1 parent 20898e8889
commit ee9c9bbc9f
2 files changed
+13 -2

No files matched your search

+5 -1
View File
@@ -22,8 +22,12 @@ export function useRouter() {
const params = useParams({ strict: false })
const search = useSearch({ strict: false })
const leafRouteId = matches[matches.length - 1]?.routeId ?? location.pathname
const pathPattern = toNextPathPattern(leafRouteId)
return {
pathname: toNextPathPattern(leafRouteId),
pathname: pathPattern,
// Match pages-router: `route` mirrors `pathname` (the bracketed
// pattern). Studio call sites read `router.route` directly.
route: pathPattern,
query: { ...params, ...search },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
push: (path: string) => router.navigate({ to: path as any }),
+8 -1
View File
@@ -23,8 +23,15 @@ export function useRouter() {
const params = useParams({ strict: false })
const search = useSearch({ strict: false })
const leafRouteId = matches[matches.length - 1]?.routeId ?? location.pathname
const pathPattern = toNextPathPattern(leafRouteId)
return {
pathname: toNextPathPattern(leafRouteId),
pathname: pathPattern,
// Next's pages-router exposes `route` and `pathname` as the same value
// — the route pattern with bracketed dynamic segments. Some studio
// code (e.g. AppLayout/BranchLink, AppLayout/ProjectDropdown) reads
// `router.route` specifically; without this it's `undefined` and
// downstream `.split('/')` calls crash.
route: pathPattern,
query: { ...params, ...search },
asPath: location.href,
basePath: router.basepath ?? '',