[英]How to set up routes in more than one place in an application. Is it possible?
我有一個Angular 2應用,正在被另一個應用作為組件庫使用。 消耗的應用程序正在使用路由,並且已在指定的模塊中對其進行了配置,並且一切正常。
問題在於,導入該庫的使用者應用程序除了需要在庫應用程序中定義的路由外,還需要更多路由。 因此,我將需要在消費者應用程序中設置這些路由。 有沒有一種方法可以在多個地方定義路線?
是的,您可以在任何模塊中設置路由。 我在這里有一個示例:APM-Final-Updated文件夾中的https://github.com/DeborahK/Angular2-GettingStarted
我在app.module.ts和product.module.ts中都有路由。 然后,我們使用import語句引入路線。
imports: [
BrowserModule,
HttpModule,
RouterModule.forRoot([
{ path: 'welcome', component: WelcomeComponent },
{ path: '', redirectTo: 'welcome', pathMatch: 'full' },
{ path: '**', redirectTo: 'welcome', pathMatch: 'full' }
]),
ProductModule
],
檢查路由器類 ,您可以動態地重新定義路由
router.resetConfig([
// ...
]);
是的,我們可以在任何模塊中設置路由。 這就是我們在Angular應用中設置延遲加載的方式。
我為了查看路線設置和延遲加載,可以檢查我的倉庫。
https://github.com/rahulrsingh09/footballdetails
appmodule代碼
@NgModule({
bootstrap: [ AppComponent],
declarations: [
AppComponent,CompetitionComponent,DropdownDirective
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule,
routing,
//TableModule, Omitted for webpack lazy loading
//TeamModule, Omitted for webpack lazy loading
MaterialModule.forRoot(),
LoadingAnimateModule.forRoot(),// temporary solution to loading
ProgressBarModule
],
providers:[CompetitionService,LoadingAnimateService ]// temporary solution to loading
})
export class AppModule {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.