2017-07-31 185 views
0

我有3级路由:app.module>admin.module>manage-users.module配置角路由问题

由于某种原因,匹配''的URL路径重定向到manage-users.module而不是HomeComponent''路径。

我在app.routing以下路线:

export const ROUTES: Routes = [ 
    { 
     path: '', 
     redirectTo: '/home', 
     pathMatch: 'full' 
    }, 
    { 
     path: 'home', 
     component: HomeComponent 
    }, 
    { 
     path: 'admin', 
     loadChildren: './admin/admin.module#AdminModule' 
    { 
     path: 'details', 
     loadChildren: './details/details.module#DetailsModule' 
    }, 
    { 
     path: 'search', 
     loadChildren: './search/search.module#SearchModule' 
    }, 
    { 
     path: 'contact', 
     loadChildren: './contact/contact.module#ContactModule' 
    }, 
]; 

@NgModule({ 
    imports: [ 
     RouterModule.forRoot(
      ROUTES, 
      { enableTracing: true, useHash: true, preloadingStrategy: NoPreloading } // <-- debugging purposes only 
     ) 
    ], 
    exports: [ 
     RouterModule 
    ] 
}) 
export class AppRoutingModule {} 

我的管理路由:

const adminRoutes: Routes = [ 
    { 
     path: 'admin', 
     component: AdminComponent, 
     children: [ 
      { 
       path: '', 
       canActivateChild: [ AdminGuard ], 
       children: [ 
        { path: 'users', 
         loadChildren: './manage-users/manage-users.module#ManageUsersModule' 
        }, 
        { 
         path: '', 
         component: AdminDashboardComponent 
        } 
       ] 
      }, 

     ], 
     canActivate: [ AdminGuard ] 
    }, 
]; 

@NgModule({ 
    imports: [ RouterModule.forChild(adminRoutes) ], 
    exports: [ RouterModule ] 
}) 
export class AdminRoutingModule { 
} 

我的管理用户的路由:

const manageUsersRoutes: Routes = [ 
    { 
     path: '', 
     component: ManageUsersComponent, 
    } 
]; 


@NgModule({ 
    imports: [ RouterModule.forChild(manageUsersRoutes) ], 
    exports: [ RouterModule ] 
}) 
export class ManageUsersRoutingModule { 
} 
+1

这些模块的导入数组是什么样的? – DeborahK

+0

他们声明和导出他们自己的组件内的功能。 – Moshe

+1

我想他想知道如何在您的功能模块导入内部配置路由器模块。因为它看起来像是在覆盖你的路线。您确定您在要素模块导入中使用了'RouterModule.forChild'吗? – cyrix

回答

1

我是问什么更多imports数组看起来像。事情是这样的:

imports: [ 
    BrowserModule, 
    HttpModule, 
    RouterModule.forRoot([ROUTES]), 
    ProductModule 
    ], 

是的,这应该是一个评论...但没有办法,我在评论所知道的格式代码。

如果您有任何类似的代码,可能会导致问题。

+0

这听起来更像他在他的功能模块中使用'RouterModule.forRoot'。 – cyrix

+1

是的,那是可能的。因此,我希望看到他们使用的进口声明的原因......不仅仅是路线本身。 – DeborahK