Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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
Javascript 角度特征布线模块-未加载子组件_Javascript_Angular_Angular2 Routing - Fatal编程技术网

Javascript 角度特征布线模块-未加载子组件

Javascript 角度特征布线模块-未加载子组件,javascript,angular,angular2-routing,Javascript,Angular,Angular2 Routing,我在AppModule中加载了一个功能模块,AppRoutingModule如下所示 const appRoutes: Routes = [ ... { path: 'move-request/:id', loadChildren: 'app/modules/move_requests/move_requests.module#MoveRequestModule' }, ... ]; const moveRequestRoutes: Routes = [

我在AppModule中加载了一个功能模块,AppRoutingModule如下所示

const appRoutes: Routes = [
  ...
  {
    path: 'move-request/:id',
    loadChildren: 'app/modules/move_requests/move_requests.module#MoveRequestModule'
  },
  ...
];
const moveRequestRoutes: Routes = [

  {
    path: '',
    component: MoveRequestFormComponent,
    data: {title: 'Move Request'}
  },
  {
    path: 'move-request-success',
    component: RequestSuccessComponent,
    data: {title: 'Move request success'}
  },
];
功能模块的路由配置如下所示

const appRoutes: Routes = [
  ...
  {
    path: 'move-request/:id',
    loadChildren: 'app/modules/move_requests/move_requests.module#MoveRequestModule'
  },
  ...
];
const moveRequestRoutes: Routes = [

  {
    path: '',
    component: MoveRequestFormComponent,
    data: {title: 'Move Request'}
  },
  {
    path: 'move-request-success',
    component: RequestSuccessComponent,
    data: {title: 'Move request success'}
  },
];
move request/:id
路由到时,我想导航到
MoveRequestFormComponent
作为默认组件,这可以正常工作,但当我调用

this.router.navigate(['/move-request-success', {}]);
MoveRequestFormComponent
中,在服务器响应之后,我得到

zone.js:665 Unhandled Promise rejection: Cannot match any routes. URL Segment: 'move-request-success' ; Zone: <root> ;

但这也不起作用,当导航到
'move-request-success'
时,它停留在MoveRequestFormComponent上。或者我应该改变方法?

您不必在AppModule中导入功能模块,因为它是延迟加载的。当您导航到
移动请求/:id/move request success
时,该路径将默认路由与
路径匹配:'
,然后它将查找该路由的及其子级。您应该将
pathMatch:'full'
添加到第一个路由,这是本例中的默认路由。由于提到的路由与第一个路由匹配,并且无法找到和匹配任何子路由,因此显示错误。

您不必在AppModule中导入功能模块,因为它是延迟加载的。当您导航到
移动请求/:id/move request success
时,该路径将默认路由与
路径匹配:'
,然后它将查找该路由的及其子级。您应该将
pathMatch:'full'
添加到第一个路由,这是本例中的默认路由。由于提到的路由与第一个路由匹配,并且无法找到和匹配任何子路由,因此显示错误。

this.router.navigate(['/move request success',{}]);。如果将/添加到路由,这意味着您使用来自根的绝对路径。你试过不穿衣服吗

编辑:

我想我明白你的问题了。导航到包含多个组件的模块,这意味着在延迟加载后,将使用加载模块中的路由器配置。这意味着

移动请求/:id

是模块的根,每个子例程都需要在url中包含模块根:

您的路线应该是
move request/:id/move request success

延迟加载模块中的URL为:

模块根目录(在您的情况下为move request/:id)+特定组件的配置路由(在您的情况下为move request success)

this.router.navigate(['/move request success',{}]);。如果将/添加到路由,这意味着您使用来自根的绝对路径。你试过不穿衣服吗

编辑:

我想我明白你的问题了。导航到包含多个组件的模块,这意味着在延迟加载后,将使用加载模块中的路由器配置。这意味着

移动请求/:id

是模块的根,每个子例程都需要在url中包含模块根:

您的路线应该是
move request/:id/move request success

延迟加载模块中的URL为:


模块根目录(在您的情况下是移动请求/:id)+特定组件的配置路由(在您的情况下是移动请求成功)

子属性中的路径可以是
路径:'/move request success'
@DhiralKaniya我已经尝试过了,但没有成功,children属性中的thanksPath可以是路径:“/move request success”@DhiralKaniya我已经尝试过了,但是没有运气,Thanksys刚刚删除了导航和配置中的“/”,没有运气,谢谢。有或没有路径匹配:'full'?谢谢,我现在明白了,我猜,我想我必须更改应用程序的架构,可能需要将两个组件从模块中取出并使用root/app模块,而不是。是的,刚刚删除了导航和配置中的“/”,不走运,谢谢。无论是否有pathMatch:“完整”?谢谢,我现在明白了,我猜,我猜我必须更改应用程序的架构,也许将这两个组件都从模块中取出并使用root/app模块,我认为这个答案是正确的,但不是move request/move request success,而是move request/:id/move request successYeah,错过了。谢谢@J.S.更新了答案我认为这个答案是正确的,但不是移动请求/移动请求成功,而是移动请求/:id/移动请求成功是的,错过了。谢谢@J.S.更新了答案