我有一個延遲加載組件和一個參數的問題。 我有兩個模塊:帶有儀表板組件(DashboardComponent)的儀表板模塊(DashboardModule)和另一個名爲user(UserModule)的模塊,其中一個組件(UserComponent)爲示例。 UserComponent用於顯示一個用戶或創建一個新用戶。 我想延遲加載模塊UserModule。所以,我在我的文件app.routing.ts配置是:現在Angular 2路由延遲加載 - 路由中的參數
export const appRoutes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: '**', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: 'user', loadChildren: 'app/user/user.module#UserModule' },
]
@NgModule({
imports: [ RouterModule.forRoot(appRoutes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
,在我的模塊用戶,我有一個文件來配置我的路線:user.routing.ts。 而我想爲我的兩種情況使用相同的路由:如果我的路由中存在某個ID,則顯示一個用戶,如果ID爲空,則創建一個用戶。 因此,我想這一點,但它不工作:
const userRoutes: Routes = [
{ path: '', component: UserComponent },
{ path: ':id', component: UserComponent } // This line does not work
];
@NgModule({
imports: [RouterModule.forChild(userRoutes)],
exports: [RouterModule]
})
export class UserRoutingModule { }
如果我有一個ID我的路線,它不工作,automaticaly路線追溯到用戶。 例如:locahost:4200/user/123不起作用,並且有一個重定向到localhost:4200 /用戶
我沒有在這個案例中找到示例,所以我希望有人會幫助我。
謝謝。
當我看到這種情況發生刪除
{ path: '**', redirectTo: '/dashboard', pathMatch: 'full' },
設定時出現錯誤的地方。你有沒有檢查控制檯,看看是否有任何錯誤發生?你也可以考慮打開路由追蹤(如這裏所示https://stackoverflow.com/questions/43618663/why-does-nothing-happen-when-i-click-on-a-link-built-with-routerlink-和-querypa/43618789#43618789)以更好地看到發生了什麼。 – DeborahK
您是否正在導入user.module中的UserRoutingModule? – Gauss