3.0.1
https://codesandbox.io/s/z611lrnq24
So I have following routes setup:
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Home',
component: Home,
props: { adops: null }
},
{
path: '/features',
name: 'Features',
component: Home,
props: { adops: 'features' },
children: [
{
path: 'hpto',
name: 'Hpto',
component: Home,
props: { adops: 'target_hpto' }
},
{
path: 'inread',
name: 'Inread',
component: Home,
props: { adops: 'target_inread' }
}
}
}
When I go to the route "/feature" I get the correct string in my adops objects adops = "features".
The moment I visit the children routes for example: /features/hpto, my prop object doesn't change (it keeps it's parent value, in this case adops = "features")
adops = target_hpto
adops = features
Your example is incomplete so it doesn't let you debug correctly, but props get passed to the child you specified them on: https://codesandbox.io/s/2p3nx1y64r
You can use the function syntax for props to change the prop depending on the route
I'm not sure what you mean by incomplete. The codesandbox I provided shows the same issue as I'm explaining.
Pay attention to the fact that each route uses the same component (Home; compared to your example).
By incomplete, I mean that you're not using router-view inside of Home
Off course not, it's set in the App.vue.
Or am I viewing this wrong? I just need to use the same component for all of em (which in this case is the Home component).
Ah, I see. Using children allow you to nest views: https://router.vuejs.org/en/essentials/nested-routes.html
Aaah I see ! I should have read better. Sorry for this inconvenience :)
I thought I could use the same component in this case. That's a bummer, quite a restriction.
Anyways, thanks for helping out!
You can! Simply don't use nested routes
@goowikns
try this.
Features props to be a function and return route.name as adopsimport Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Home',
component: Home,
props: { adops: null }
},
{
path: '/features',
name: 'Features',
component: Home,
props: (route) => ({ adops: route.name }),
children: [
{
path: 'hpto',
name: 'Hpto',
component: Home
},
{
path: 'inread',
name: 'Inread',
component: Home
}
}
}
Most helpful comment
@goowikns
try this.
Featuresprops to be a function and returnroute.nameasadops