Angular 路由器订购?

Angular Router Ordering?

请解释以下 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. 常量路线:路线= [ { 小路: '', 可以激活:[AuthGuard], 组件:主要组件, children: [ { 小路: '', 组件:DashboardComponent }, { 路径:'items/add', 组件:AddItemComponent }, { 路径:'items/:id', 组件:EditWrapperComponent }, { 路径:'items/:account/:id', 组件:EditWrapperComponent }, { 路径:'items/:type/sandbox', 组件:SandboxComponent } ] } ];

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

不知道为什么请大家帮忙解释:)

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