Skip to content

Commit

Permalink
fix(router-view): render the slot when there is no match
Browse files Browse the repository at this point in the history
Close #385
  • Loading branch information
posva committed Jul 24, 2020
1 parent 9580bea commit bae42d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 6 additions & 0 deletions e2e/specs/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
}
3 changes: 2 additions & 1 deletion e2e/transitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Parent: RouteComponent = {
<div class="parent">
<h2>Parent</h2>
{{ transitionName }}
<router-view class="child-view" v-slot="{ Component }">
<router-view class="child-view" v-slot="{ Component, route }">
<transition :name="transitionName">
<component :is="Component" />
</transition>
Expand Down Expand Up @@ -95,6 +95,7 @@ const app = createApp({
<li><router-link to="/parent">/parent</router-link></li>
<li><router-link to="/parent/foo">/parent/foo</router-link></li>
<li><router-link to="/parent/bar">/parent/bar</router-link></li>
<li><router-link to="/not-found">Not existing</router-link></li>
</ul>
<router-view class="view" v-slot="{ Component }">
<transition name="fade" mode="out-in">
Expand Down
16 changes: 8 additions & 8 deletions src/RouterView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -50,14 +50,14 @@ export const RouterViewImpl = defineComponent({
const viewRef = ref<ComponentPublicInstance>()

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
Expand Down Expand Up @@ -97,7 +97,7 @@ export const RouterViewImpl = defineComponent({
// pass the vnode to the slot as a prop.
// h and <component :is="..."> both accept vnodes
slots.default
? slots.default({ Component: component, route: matchedRoute })
? slots.default({ Component: component, route })
: component
)
}
Expand Down

0 comments on commit bae42d4

Please sign in to comment.