带有延迟加载模块和子路由的Angular 7路由器'**'通配符不起作用?

带有延迟加载模块和子路由的Angular 7路由器'**'通配符不起作用?

问题描述:

我正在尝试使用来自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.