How to define default route with parameters in Angular Component Router?

后端 未结 2 1762
-上瘾入骨i
-上瘾入骨i 2021-01-20 22:18

I want to have a default route in my sub-component (set with useAsDefault: true) and to have parameters automatically passed to it. I cannot find anywhere in do

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-20 23:01

    So I solved my problem in following way: I added a default route without params, and I immediately redirect from $routerOnActivate

    public $routeConfig = [
        { path: '/', component: 'employeeListComponent', name: 'GroupRedirect', useAsDefault: true},    
        { path: '/:group/:filter', component: 'employeeListComponent', name: 'Group'}
        { path: '/details/:employeeId/...', component: 'profileComponent', name: 'EmployeeProfile'},
    ]
    

    and then in the controller:

    public $routerOnReuse(route) {
      if (!route.params.group) {
        this.$router.navigate(['Group', { group: 'status', filter: 'active' }]);
      }
    }
    

提交回复
热议问题