0

我有 3 个级别的路由:app.module> admin.module> manage-users.module

出于某种原因,匹配的 URL 路径''重定向到''路径 inmanage-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 {
}
4

1 回答 1

1

我在问更多导入数组的样子。像这样的东西:

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

是的,这应该是一条评论……但我不知道如何在评论中格式化代码。

如果您有任何这样的代码,那可能会导致问题。

于 2017-07-31T23:42:55.680 回答