【发布时间】:2019-04-10 05:46:11
【问题描述】:
我正在尝试在我的 Angular 应用程序中实现延迟加载。 这是我的路线:
app-routing.module.ts
const routes: Routes = [
{
path: '',
loadChildren: './customer/customer.module#CustomerModule',
pathMatch: 'full'
}
];
在模块中:
imports: [RouterModule.forRoot(routes)],
customer-routing.module.ts
export const routes: Routes = [
{ path: '', component: ComparePageComponent },
{ path: 'funds', component: FundSelectionComponent },
{ path: ':service', component: ComparePageComponent },
{ path: '**', component: PageNotFoundComponent },
];
在模块中:
imports: [
RouterModule.forChild(routes)
],
现在,我有一个逻辑,可以在没有路径参数时加载 /profile 页面,即当 url 为 '' (this._router.navigate(['', 'profile'])) 时,我已经在我的客户模块 { path: ':service', component: ComparePageComponent } 中定义了路径
但是,当应用程序运行时,它会导致以下错误:
ERROR 错误:未捕获(在承诺中):错误:无法匹配任何路由。网址 段:'profile' 错误:无法匹配任何路由。网址段: '轮廓' 在 ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirect
不确定我哪里出错了。
【问题讨论】:
-
个人资料和服务是如何关联的?
-
@Sajeetharan profile 是 url 中的路径参数。 service 是我指定为 :service 的路径参数的占位符
-
@SiddAjmera,这也发生在 /funds 路径上。它没有采用客户模块中提到的任何路径
-
@SiddAjmera,你的意思是说我必须在 app-routing.module.ts 中有一个空路由的组件?
-
@SiddAjmera 是的,我是