问题描述
我正在尝试使用来自 Angular 路由器的通配符**"创建默认路由.该默认路由将加载一个惰性模块,然后它必须解决自己的路由.问题是,当我有以下配置时,它没有按预期解决:
I'm trying to create a default route using the wildcard '**' from Angular's router. That default route will load a lazy module and then it will have to solve its own routes. The problem is that when I have the following configuration it does not resolve as expected:
export const routes = [
{
path: '',
component: 'DashboardComponent'
},
{
path: '**',
loadChildren: './lazy/lazy.module#LazyModule'
}
];
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(routes)
],
declarations: [AppComponent]
bootstrap: [AppComponent]
})
export class AppModule {}
const routes = [
{
path: '',
component: MainComponent
}
{
path: 'hello', // hoping to pick up the wildcard and resolve the route
component: HelloComponent
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes)
],
declarations: [
AnyComponent,
EditComponent
]
})
export default class LazyModule {}
例如.使用 mydomain.com/hello,它不会向我显示 HelloComponent,而是向我显示 MainComponent.
For example. With mydomain.com/hello it does not show me the HelloComponent, it shows me the MainComponent.
我的配置有问题还是不应该像这样工作?
Is there something wrong with my configuration or should it not work like this?
提前致谢.
推荐答案
我相信您必须重定向到实际路线.有一些与此相关的主题,这里有一个.此外,根据 Angular 的示例,您可能需要从 LazyModule 导出 RouterModule.
I believe you have to redirect to an actual route. There are a few topics related to this, here is one. Also per Angular's examples, you might have to export your RouterModule from LazyModule.
这篇关于带有延迟加载模块和子路由的 Angular 7 路由器“**"通配符不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!