diff --git a/apps/studio/compat/next/compat/router.ts b/apps/studio/compat/next/compat/router.ts index a208e9dfa28..09f6aaf564d 100644 --- a/apps/studio/compat/next/compat/router.ts +++ b/apps/studio/compat/next/compat/router.ts @@ -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 }), diff --git a/apps/studio/compat/next/router.ts b/apps/studio/compat/next/router.ts index 5316054d625..eb818f871ec 100644 --- a/apps/studio/compat/next/router.ts +++ b/apps/studio/compat/next/router.ts @@ -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 ?? '',