三层路由没有问题, 第四层出现问题了
vue Router
Go to Foo
Go to Bar
// /user/foo
const Foo = { template: ` 第三级
`}
const Bar = { template: ` /user/bar
` }
const User = {template: 'User {{ $route.params.id }}
'}
const userFoo = {template :`第四级
`}
const userBar = {template :'Bar
'}
const userFooChildren = `Hello, I am four
`
const router = new VueRouter({
routes:[
{ path:'/user/:id' ,component:User},
{ path: '/foo', component: Foo ,
children: [
{ path : 'userfoo', component: userFoo ,
children: [
{
path : 'fooFour/:1',
component: userFooChildren
}
]
}
]
},
{ path: '/bar', component: Bar ,
children: [
{path: 'userBar', component: userBar }
]
}
]
})
const app = new Vue({
router
}).$mount('#app')
这是报错 Uncaught Error: [vue-router] route config "component" for path: fooFour/:1 cannot be a string id. Use an actual component instead.
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
试试改成这样?
看报错信息是
/:1出的问题,不能用1来作为string key再来是,建议把斜杠补全,虽然可能影响不大
以上是错的
发现了,你的代码写错的,建议下次问问题好好整理一下代码的格式缩进什么的
应该这么写