如果我们在angular的主路由模块中有这样的东西:
const routes: Routes = [
{
path: 'test',
loadChildren: () =>
import('./test/test.module').then((module) => module.TestModule),
},
{
path:'**',
redirectTo:'notFounded'
},
{
path:'notFounded',
component:NotFoundedComponent
}
];
这在名为“Test”的模块的其他路由器中:
const routes: Routes = [{ path: 'compOfPage', component: TestComponent }];
如果我们访问 /test
路由(Test 路由模块中路由的父路由),即使没有任何与此路由关联的组件,它也不会重定向到 notFounded 页面,我们可以在 chrome dev 中看到加载 TestModule 的工具。
如何防止路由器加载与任何组件无关的父路由?我知道我们可以手动将父级重定向到错误页面,但是,对于许多模块,这不是一个优雅的解决方案。