Angular routing keep child parameters

空扰寡人 提交于 2021-02-10 16:16:01

问题


I have the following route configuration:

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
    canActivate: [AuthGuard],
    children: [
      {
        component: DashboardComponent,
        path: ''
      },
      {
        component: UnitComponent,
        path: 'unit/:serialnumber',
        children: [
                  { path: '', redirectTo: 'realtime', pathMatch: 'full'},
          {
            path: 'manager',
            component: UnitManagerComponent,
            canActivate: [SysAdminGuard]
          },
          { path: 'realtime', component: UnitRealtimeComponent },
          { path: 'history', component: UnitHistoryComponent },
          { path: 'consumption', component: UnitConsumptionComponent },
          { path: 'consumption/:range', component: UnitConsumptionComponent },
          { path: 'edit', component: UnitEditComponent }
        ]
      }
    ]
  }
...

image that i am in current route state

http://127.0.0.1:4200/#/unit/000000003/consumption/monthly

and i want to navigate to another unit with a different serialnumber:

http://127.0.0.1:4200/#/unit/000000001/consumption/monthly

if i make

this.router.navigate(['/unit','000000001'])

i will go to http://127.0.0.1:4200/#/unit/000000001/realtime

is there any way to change a specific parameter in the route and keep the childs route ?

来源:https://stackoverflow.com/questions/49784350/angular-routing-keep-child-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!