我希望在我的子组件中有一个默认路由(使用useAsDefault:true
设置),并自动传递参数。我无法在文档中找到如何实现它的任何地方。
我有一个具有以下路由的父组件:
$routeConfig = [
{ path: '/employees/...', component: 'employeesComponent', name: 'Employees'}
]
以及一个包含以下内容的子组件:
$routeConfig = [
{ path: '/:group/:filter', component: 'employeeListComponent', name: 'Group', useAsDefault: true}
{ path: '/details/:employeeId/...', component: 'profileComponent', name: 'EmployeeProfile'}
]
当然,这会失败并提示:
参数中未包含'group'的路由生成器
。我无法想出如何在第一个路由中传递一些默认参数。不过,我通过创建另一个没有参数的路由,并将其用作默认值来解决了这个问题:{ path: '/all', component: 'employeeListComponent', name: 'All', useAsDefault: true}
但是,这当然不是理想的。到目前为止,我还没有想出更好的方法,只能使用没有参数的路由,然后立即重定向到一些默认参数。难道没有更好的方法吗?