From: Eduardo San Martin Morote Date: Fri, 24 Jul 2020 08:39:18 +0000 (+0200) Subject: fix(router-view): render the slot when there is no match X-Git-Tag: v4.0.0-beta.4~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bae42d41c2240947e5b649e568cad274214c6346;p=thirdparty%2Fvuejs%2Frouter.git fix(router-view): render the slot when there is no match Close #385 --- diff --git a/e2e/specs/transitions.js b/e2e/specs/transitions.js index 4909b63e..e5e79546 100644 --- a/e2e/specs/transitions.js +++ b/e2e/specs/transitions.js @@ -43,6 +43,12 @@ module.exports = { .assert.cssClassPresent('.view.home', 'fade-enter-active') .waitForElementNotPresent('.view.home.fade-enter-active', TIMEOUT) + .click('li:nth-child(5) a') + .assert.cssClassPresent('.view.home', 'fade-leave-active') + .waitForElementNotPresent('.view.home', TIMEOUT) + .click('li:nth-child(2) a') + .assert.cssClassPresent('.view.parent', 'fade-enter-active') + .end() }, } diff --git a/e2e/transitions/index.ts b/e2e/transitions/index.ts index 15356724..9a4dc9ca 100644 --- a/e2e/transitions/index.ts +++ b/e2e/transitions/index.ts @@ -47,7 +47,7 @@ const Parent: RouteComponent = {

Parent

{{ transitionName }} - + @@ -95,6 +95,7 @@ const app = createApp({
  • /parent
  • /parent/foo
  • /parent/bar
  • +
  • Not existing
  • diff --git a/src/RouterView.ts b/src/RouterView.ts index 0b15686a..39afae54 100644 --- a/src/RouterView.ts +++ b/src/RouterView.ts @@ -38,10 +38,10 @@ export const RouterViewImpl = defineComponent({ setup(props, { attrs, slots }) { __DEV__ && warnDeprecatedUsage() - const route = inject(routeLocationKey)! + const injectedRoute = inject(routeLocationKey)! const depth = inject(viewDepthKey, 0) const matchedRouteRef = computed( - () => (props.route || route).matched[depth] + () => (props.route || injectedRoute).matched[depth] ) provide(viewDepthKey, depth + 1) @@ -50,14 +50,14 @@ export const RouterViewImpl = defineComponent({ const viewRef = ref() return () => { + const route = props.route || injectedRoute const matchedRoute = matchedRouteRef.value - if (!matchedRoute) { - return null - } + const ViewComponent = matchedRoute && matchedRoute.components[props.name] - const ViewComponent = matchedRoute.components[props.name] if (!ViewComponent) { - return null + return slots.default + ? slots.default({ Component: ViewComponent, route }) + : null } // props from route configration @@ -97,7 +97,7 @@ export const RouterViewImpl = defineComponent({ // pass the vnode to the slot as a prop. // h and both accept vnodes slots.default - ? slots.default({ Component: component, route: matchedRoute }) + ? slots.default({ Component: component, route }) : component ) }