Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度布线和铺设加载模块的问题_Angular - Fatal编程技术网

Angular 角度布线和铺设加载模块的问题

Angular 角度布线和铺设加载模块的问题,angular,Angular,给定以下路由配置: 以下模块在AppModule const routes: Routes = [ ... { path: "lazy", loadChildren: "app/modules/lazymodule#LazyModule" }, { path: "**", component: DemoComponent, pathMatch: "full" } ] @NgModule({ imports: [RouterModul

给定以下路由配置:

以下模块在
AppModule

const routes: Routes = [
 ...
  {
    path: "lazy",
    loadChildren: "app/modules/lazymodule#LazyModule"
  },
  {
    path: "**",
    component: DemoComponent,
    pathMatch: "full"
  }
]

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
const routes: Routes = [
  {
    path: "",
    component: LazyComponent,
    pathMatch: "full"
  },
  {
    path: ":test",
    component: TestComponent
  },
  {
    path: "try",
    component: TryComponent,
    pathMatch: "full",

  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)]
})
以下模块在
LazyModule

const routes: Routes = [
 ...
  {
    path: "lazy",
    loadChildren: "app/modules/lazymodule#LazyModule"
  },
  {
    path: "**",
    component: DemoComponent,
    pathMatch: "full"
  }
]

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
const routes: Routes = [
  {
    path: "",
    component: LazyComponent,
    pathMatch: "full"
  },
  {
    path: ":test",
    component: TestComponent
  },
  {
    path: "try",
    component: TryComponent,
    pathMatch: "full",

  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)]
})
加载
LazyModule
后,我可以导航到
TestComponent
,例如

this.router.navigate(["/lazy", "hello"])
但不是通过
TryComponent

this.router.navigate(["/lazy/try"])

最后一个有什么问题吗?

/lazy/try
匹配为:

{
    path: ":test",
    component: TestComponent
}
因此,应该使用
try
作为
:test
参数的值导航到
TestComponent

如果要更改该路径,请更改路由顺序,使路径为“try”的路由位于路径为“test”的路由之前