角度路由器订购?

问题描述 投票:0回答:1

请解释下面的2个代码片段之间的区别:

  1. const routes: Routes = [ { path: '', canActivate: [AuthGuard], component: MainComponent, children: [ { path: '', component: DashboardComponent }, { path: 'items/add', component: AddItemComponent }, { path: 'items/:type/sandbox', component: SandboxComponent }, { path: 'items/:id', component: EditWrapperComponent }, { path: 'items/:account/:id', component: EditWrapperComponent } ] } ];
  2. const routes:Routes = [{path:'',canActivate:[AuthGuard],component:MainComponent,children:[{path:'',component:DashboardComponent},{path:'items / add',component:AddItemComponent}, {path:'items /:id',component:EditWrapperComponent},{path:'items /:account /:id',component:EditWrapperComponent},{path:'items /:type / sandbox',component:SandboxComponent}] }];

当我调用localhost:4200/items/app/sandbox(app是类型)但代码片段2不起作用时,代码片段1也可以正常工作。

我不知道为什么这样请帮忙解释一下:)

angular router
1个回答
1
投票

在代码片段2中,由于排序,/items/app/sandbox被路由到'items/:account/:id

© www.soinside.com 2019 - 2024. All rights reserved.