fix(nuxt): include missing <NuxtPage> component props (#9204)

Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
Damian Głowala 2022-11-21 14:03:22 +01:00 committed by GitHub
parent a4e0a64f33
commit 4f2bfbe5c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -40,7 +40,7 @@ export default defineComponent({
default: (routeProps: RouterViewSlotProps) => { default: (routeProps: RouterViewSlotProps) => {
if (!routeProps.Component) { return } if (!routeProps.Component) { return }
const key = generateRouteKey(props.pageKey, routeProps) const key = generateRouteKey(routeProps, props.pageKey)
const done = nuxtApp.deferHydration() const done = nuxtApp.deferHydration()
const hasTransition = !!(props.transition ?? routeProps.route.meta.pageTransition ?? defaultPageTransition) const hasTransition = !!(props.transition ?? routeProps.route.meta.pageTransition ?? defaultPageTransition)
@ -62,7 +62,9 @@ export default defineComponent({
} }
} }
}) as DefineComponent<{ }) as DefineComponent<{
name?: string, name?: string
transition?: boolean | TransitionProps
keepalive?: boolean | KeepAliveProps
route?: RouteLocationNormalized route?: RouteLocationNormalized
pageKey?: string | ((route: RouteLocationNormalizedLoaded) => string) pageKey?: string | ((route: RouteLocationNormalizedLoaded) => string)
[key: string]: any [key: string]: any

View File

@ -12,7 +12,7 @@ const interpolatePath = (route: RouteLocationNormalizedLoaded, match: RouteLocat
.replace(/:\w+/g, r => route.params[r.slice(1)]?.toString() || '') .replace(/:\w+/g, r => route.params[r.slice(1)]?.toString() || '')
} }
export const generateRouteKey = (override: string | ((route: RouteLocationNormalizedLoaded) => string), routeProps: RouterViewSlotProps) => { export const generateRouteKey = (routeProps: RouterViewSlotProps, override?: string | ((route: RouteLocationNormalizedLoaded) => string)) => {
const matchedRoute = routeProps.route.matched.find(m => m.components?.default === routeProps.Component.type) const matchedRoute = routeProps.route.matched.find(m => m.components?.default === routeProps.Component.type)
const source = override ?? matchedRoute?.meta.key ?? (matchedRoute && interpolatePath(routeProps.route, matchedRoute)) const source = override ?? matchedRoute?.meta.key ?? (matchedRoute && interpolatePath(routeProps.route, matchedRoute))
return typeof source === 'function' ? source(routeProps.route) : source return typeof source === 'function' ? source(routeProps.route) : source

View File

@ -362,7 +362,7 @@ describe('pages:generateRouteKey', () => {
for (const test of tests) { for (const test of tests) {
it(test.description, () => { it(test.description, () => {
expect(generateRouteKey(test.override, test.route)).to.deep.equal(test.output) expect(generateRouteKey(test.route, test.override)).to.deep.equal(test.output)
}) })
} }
}) })