I am using named views inside my vue-router. Inside of both components I need to get the props.
The following codes shows the definition of the routes. The first entry is not working. Inside the component the props will stay undefined. So the Breadcrumb and the Collection component is getting no property
The second example works, because there is just one component:
const routes = [
{
path: '/:cid',
name: 'collection',
props: true,
components: {
default: Collection,
breadcrumb: Breadcrumb
}
},
{
path: '/:cid/:iid',
name: 'item',
props: true,
component: Item
},
]
I think the the props property is just working, when there is just one component.
I didn't find a solution inside the documentation so any help is welcome.
Vue Router 4 provides multiple ways of doing this: from setting the props property on the route record to true and automatically passing all params as props, setting the props property to a static object to provide static props, or setting it to a function that returns the desired props.
Yes, you can use multiple components and pass props to each one:
const router = new VueRouter({
mode: 'history',
routes: [
{
path: '/',
components: {
default: Home,
foo: Foo
},
props: {
default: { name: 'Home' },
foo: { name: 'Foo' }
}
}
]
})
http://jsfiddle.net/jonataswalker/ykf0uv0d/
See related discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With