2017-07-31 101 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