Passing props and slots to named views (multiple components) #2215
-
Hey, My question basically refers to the same section in the docs, but I need this for a route that has named views with different components each haveing different props I need to pass over. For a single component per route this appears to be done like this with I use names views how do I set this I eventually have various routes that potentially utilize multiple named views. This is the excerpt from my tests const routes = [
{ ... route 0 ... },
{ ... route 1 ... },
{
name: 'favs',
path: '/favourites',
component: () => import('PageFavourites.vue'),
},
{ ... route 3 ... },
];
/**
* some code in between that evaluates env vars or whatnot and
* makes "descisions" that eventually may end up doing this to route #2
*/
delete routes[2].component; // drop single entry
// create named views
routes[2].components = {
default: () => import('PageFavourites.vue'),
secondary: () => import('Sniffer.vue'),
};
// doesn't seem to help
routes[2].props = {
default: true,
SnifferVue: true
}; Within my App / Layout component I have this template snippet using a <!-- always render the default -->
<RouterView />
<!-- simple check if there are multiple components for this route -->
<RouterView v-if="$route.matched[0].components" v-slot="{ Component }"
name="secondary">
<component :is="Component" v-bind:foo="someVariable"></component>
</RouterView> The I also tried <RouterView v-if="$route.matched[0].components" name="SnifferVue"
v-slot="{ Component }"
v-bind:foo="someVariable">
... Are ther other attributes/props/parameter for Any hints welcome! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Using the You should just need to use I've put together a Playground based on your code to demonstrate it working correctly: |
Beta Was this translation helpful? Give feedback.
Using the
props: true
setting it only required if you want to pass props from the router itself, e.g. based on the URL. If you need to pass props from the parent component then you don't need that setting.You should just need to use
:foo="someVariable"
on the<component>
tag, much like you have in one of the code snippets you shared. I don't see anything wrong with that code that would prevent it from working.I've put together a Playground based on your code to demonstrate it working correctly: