配置角度路由时遇到问题

时间:2017-07-31 23:19:25

标签: angular angular-router

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

由于某种原因,与''匹配的网址路径会重定向到''中的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 个答案:

答案 0 :(得分:1)

我问的是更多导入数组的样子。像这样:

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

是的,这应该是一个评论...但我不知道在评论中格式化代码。

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