router
router copied to clipboard
Support for multiple route-views inside a transition/keep-alive
What problem does this feature solve?
The following is not possible if the my-modal
component has transitions.
<my-modal>
<template #default>
<router-view>
</template>
<template #footer>
<router-view name="footer">
</template>
</my-modal>
If there's no footer
slot, we can of course use the pattern suggested in the Vue Router docs and use router-view
's slot props:
<router-view #default="{ Component }">
<my-modal>
<template #default>
<component :is="Component" />
</template>
</my-modal>
</router-view>
But then there's no (apparent) way to solve this usecase for the footer
slot.
What does the proposed API look like?
Whatever is most practical.
Provide all named views on the main router-view:
<router-view #default="{ Component, Components }">
<component :is="Component" />
<component :is="Components.Footer" />
</router-view>
Or enable nested router-views
to work with named routes? (This is the solution the Vue Discord chat thought was working today for this problem)
Do you have a boiled down snippet of what you are trying to achieve? It would help understanding
Sure!
Effectively what's in the first snippet in my original post.
<my-modal>
<template #default>
<router-view>
</template>
<template #footer>
<router-view name="footer">
</template>
</my-modal>
However, since my-modal
uses transitions [0], we instead have to do the following. The default
content works fine, but then there's no way to get content from the route-view footer
to the footer
slot in MyModal.
<router-view #default="{ Component }">
<my-modal>
<template #default>
<component :is="Component" />
</template>
<template #footer>
<!-- how do we get the router-view below to work here? -->
<router-view name="footer">
</template
</my-modal>
</router-view>
[0] - MyModal looks something like
<transition>
<div>
<slot />
</div>
<div>
<slot name="footer" />
</div>
</transition>
Ah I see now! Yeah that Components variable might be the easiest way
After taking a look, this is currently not possible because one RouterView only renders itself and to be able to provide a Components
property on the slot, we would have to render all views. So this would require activation through a prop
but that simply doesn't sound right.
If your modal looks like
<transition>
<div>
<slot />
</div>
<div>
<slot name="footer" />
</div>
</transition>
Then it doesn't matter how you pass the views as they aren't wrapped by the transition anyway.
Or enable nested router-views to work with named routes? (This is the solution the Vue Discord chat thought was working today for this problem)
That would break the existing usage of nested named views.
Let's give this more thinking. In any case, it definitely requires going through an RFC.
I'm using fragment pages a lot. Now you can mount Vue on body element. There is no need for containers.
@baybal - do you have an example of what you're referring to? I'm not sure how any of that relates to this issue.
It just hit me it is not related