Skip to content

Commit

Permalink
fix(view): render slot with no match
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Apr 21, 2020
1 parent b83d8aa commit 5873296
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion e2e/transitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const app = createApp({
</ul>
<router-view class="view" v-slot="{ Component, props }">
<transition name="fade" mode="out-in">
<component :is="Component" v-bind="props"></component>
<component v-if="Component" :is="Component" v-bind="props"></component>
</transition>
</router-view>
</div>
Expand Down
9 changes: 5 additions & 4 deletions src/components/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const View = (defineComponent({
)

const propsData = computed(() => {
// propsData only gets called if ViewComponent.value exists and it depends on matchedRoute.value
// propsData only gets called if ViewComponent.value exists and it depends
// on matchedRoute.value
const { props } = matchedRoute.value!
if (!props) return {}
if (props === true) return route.value.params
Expand Down Expand Up @@ -77,17 +78,17 @@ export const View = (defineComponent({

let Component = ViewComponent.value
const componentProps: Parameters<typeof h>[1] = {
// only compute props if there is a matched record
...(Component && propsData.value),
...attrs,
onVnodeMounted,
onVnodeUnmounted,
ref: viewRef,
}

// NOTE: we could also not render if there is no route match
const children =
Component &&
slots.default &&
slots.default({ Component, props: componentProps })
slots.default && slots.default({ Component, props: componentProps })

return children
? children
Expand Down

0 comments on commit 5873296

Please sign in to comment.