Angular 6中的延迟加载导致无法匹配任何路由

Angular 6中的延迟加载导致无法匹配任何路由,angular,angular-routing,Angular,Angular Routing,我正在尝试在Angular应用程序中实现延迟加载。 以下是我的路线: 应用程序路由.module.ts const routes: Routes = [ { path: '', loadChildren: './customer/customer.module#CustomerModule', pathMatch: 'full' } ]; export const routes: Routes = [ { path: '', component: Compa

我正在尝试在Angular应用程序中实现延迟加载。 以下是我的路线:

应用程序路由.module.ts

const routes: Routes = [
  {
    path: '',
    loadChildren: './customer/customer.module#CustomerModule',
    pathMatch: 'full'
  }
];
export const routes: Routes = [
  { path: '', component: ComparePageComponent },
  { path: 'funds', component: FundSelectionComponent },
  { path: ':service', component: ComparePageComponent },
  { path: '**', component: PageNotFoundComponent },
];
在模块中:

  imports: [RouterModule.forRoot(routes)],
客户路由.module.ts

const routes: Routes = [
  {
    path: '',
    loadChildren: './customer/customer.module#CustomerModule',
    pathMatch: 'full'
  }
];
export const routes: Routes = [
  { path: '', component: ComparePageComponent },
  { path: 'funds', component: FundSelectionComponent },
  { path: ':service', component: ComparePageComponent },
  { path: '**', component: PageNotFoundComponent },
];
在模块中:

imports: [
    RouterModule.forChild(routes)
  ],
现在,我有了一个逻辑,当没有路径参数时,即当url为“”(this.\u router.navigate(['''profile']))时,我将加载
/profile
页面,我已经在我的客户模块
{path:':service',component:ComparePageComponent}

但是,当应用程序运行时,会导致以下错误:

错误:未捕获(承诺中):错误:无法匹配任何路由。统一资源定位地址 段:“配置文件”错误:无法匹配任何路由。URL段: “个人资料” 在ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirect


不太确定我哪里出错。

您已经发出了导航路径。您应该使用
/
根目录启动导航


this.\u router.navigate(['/','profile'])

您已经发出了导航路径。您应该使用
/
根目录启动导航


this.\u router.navigate(['/','profile'])
您的
AppRoutingModule
只有一条路由可以为用户加载
CustomerModule
。但是在一条空的路线上(
'

但是,当您将用户导航到
/profile
路径时,Angular正在您的AppRoutingModule中查找与
'profile'
路径对应的配置

但是由于它无法在那里找到它,它抛出了这个错误

要使角度查看超出空路径(
“”
),它需要使用
前缀
路径匹配
策略,默认情况下使用该策略,除非您将其指定为
完整


您可能希望尝试从AppRoutingModule中的路由配置中删除
路径匹配:“full”
,以修复它。

您的
AppRoutingModule
只有一条路由为用户加载
CustomerModule
。但是在一条空的路线上(
'

但是,当您将用户导航到
/profile
路径时,Angular正在您的AppRoutingModule中查找与
'profile'
路径对应的配置

但是由于它无法在那里找到它,它抛出了这个错误

要使角度查看超出空路径(
“”
),它需要使用
前缀
路径匹配
策略,默认情况下使用该策略,除非您将其指定为
完整



您可能需要尝试从AppRoutingModule中的路由配置中删除
路径匹配:“full”
,以修复它。

配置文件和服务的关系如何?@Sajeetharan profile是url中的路径参数。服务是我指定为的路径参数的占位符:service@SiddAjmera,这也适用于/资金路径。它不采用客户手册中提到的任何路径module@SiddAjmera,您的意思是说我必须在app routing.module.ts中为空路由设置一个组件?@SiddAjmera是的,我知道配置文件和服务是如何关联的?@Sajeetharan profile是url中的路径参数。服务是我指定为的路径参数的占位符:service@SiddAjmera,这也适用于/资金路径。它不采用客户手册中提到的任何路径module@SiddAjmera,您的意思是说我必须在app routing.module.ts?@SiddAjmera中为空路由设置一个组件是的,我知道这没有帮助是客户模块路径
。/customer/customer.module#CustomerModule'
对吗,这就是路径。你能检查一下这是否正常。_router.navigate(['/funds'])
正常工作吗?答案来自@SiddAjmera的帖子。谢谢你这没有帮助是客户模块路径
。/customer/customer.module#CustomerModule'
对吗?是的,这就是路径。你能检查一下
这个吗。_router.navigate(['/funds'])
工作吗?从@SiddAjmera的帖子中得到答案。感谢您从AppRoutingModule中删除pathMatch:“full”并将其添加到CustomerRoutingModule中,解决了以下问题:提供空路径的最佳做法是什么??我们应该在AppRoutingModule或FeatureRoutingModule中使用路径匹配吗??我只是想确保我遵循最佳实践。这取决于要求。对于使用
pathMatch
,没有任何现成的或固定的最佳实践。在本例中,我们希望检查
前缀
es,而不是完整的
路径
。因此,我们不应该指定
路径
,因为默认情况下它的值是
前缀
,除非指定为
full
从AppRoutingModule中删除路径匹配:“full”并将其添加到CustomerRoutingModule修复了这个问题:当提供空路径时,最佳做法是什么??我们应该在AppRoutingModule或FeatureRoutingModule中使用路径匹配吗??我只是想确保我遵循最佳实践。这取决于要求。对于使用
pathMatch
,没有任何现成的或固定的最佳实践。在本例中,我们希望检查
前缀
es,而不是完整的
路径
。因此,我们不应该指定
路径
,因为它的默认值是
前缀
,除非指定为
完整