mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 13:49:09 +03:00
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:
1 parent
20898e8889
commit
ee9c9bbc9f
2 files changed
+13
-2
No files matched your search
@@ -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 }),
|
||||
|
||||
@@ -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 ?? '',
|
||||
|
||||
Reference in new issue
Block a user