Angular通配符路由
在写route的时候,需要将静态路由写在通配符路由之前,因为路由是从上之下解析的静态路由可能会被识别成通配符路由,导致页面呈现的是通配路由的component。
参考:angular路由
举个例子:
const routes = [{
path: '',
component: MainComponent,
children: [{
path: '',
pathMatch: 'full',
redirectTo: 'test1'
}, {
path: 'test',
children: [{
path: '',
component: TestComponent,
}, {
path: 'test-child', // 静态路由
component: TestChildComponent
}, {
path: ':child-kind', //通配路由
component: TestChildKindComponent
}]
}
}]
}];
若静态路由写在通配路由下,则跳转到’test-child’的路径下时,不会编译TestChildComponent,而是会被识别成:child-kind,编译TestChildKindComponent。