Skip to content

how to use render function to return router-view-slot? #2152

Discussion options

You must be logged in to vote

Here's an example:

In that example, I'm importing RouterView directly, rather than using resolveComponent, but either way should work.

In general, <component :is="foo"> becomes h(foo). But in the specific case of RouterView, the Component slot prop is already a VNode, so the extra h() call can be skipped:

h(RouterView, null, ({ Component }) => Component)

If you wanted to write that out in full it might be something like this:

h(RouterView, null, {
  default({ Component }) {
    return Component ? h(Component) : null
  }
})

The code above also needs to take account of the initial value of Component being undefined.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants