1

尝试解决路由子问题但无法解决。如果我单击管理按钮不起作用,则不是管理部分的重定向。如何解决此问题。

演示:https ://stackblitz.com/edit/angular-3mngoh?file=src/app/approuting.module.ts

批准.module.ts:

const routes: Routes = [ 
 {
 path: 'admin',
 component: AdminSectionComponent,
 children: [ 
 { path: '', loadChildren: () => import('./adminsection/layout/layout.module').then(m =>  m.LayoutModule) },
 { path: 'login', loadChildren: () => import('./adminsection/login/login.module').then(m => m.LoginModule) },
 { path: 'signup', loadChildren: () => import('./adminsection/signup/signup.module').then(m => m.SignupModule) },
 { path: 'error', loadChildren: () => import('./adminsection/server-error/server-error.module').then(m => m.ServerErrorModule) },
 { path: 'access-denied', loadChildren: () => import('./adminsection/access-denied/access-denied.module').then(m => m.AccessDeniedModule) },
 { path: 'not-found', loadChildren: () => import('./adminsection/not-found/not-found.module').then(m => m.NotFoundModule) },
 { path: '**', redirectTo: 'not-found' }

 ]
 },....etc
4

1 回答 1

1

路由没有发生,因为从您的 UI 中单击 admin 它寻找 /login 显示未找到并给出错误。所以在分析后我发现在 AdminSection-RoutingModule.ts 的评论行中发生了冲突。这是你的代码路由数组用下面的代码替换它。

您的代码:-----------

  const routes: Routes = [
  {path:'',component:AdminSectionComponent,

  children:[

 { path: '', loadChildren: () => import('./layout/layout.module').then(m => m.LayoutModule), canActivate: [AuthGuard] },
    { path: 'login', loadChildren: () => import('./login/login.module').then(m => m.LoginModule) },
    { path: 'signup', loadChildren: () => import('./signup/signup.module').then(m => m.SignupModule) },
    { path: 'error', loadChildren: () => import('./server-error/server-error.module').then(m => m.ServerErrorModule) },
    { path: 'access-denied', loadChildren: () => import('./access-denied/access-denied.module').then(m => m.AccessDeniedModule) },
    { path: 'not-found', loadChildren: () => import('./not-found/not-found.module').then(m => m.NotFoundModule) },
    { path: '**', redirectTo: 'not-found' }
  ]}

];

替换代码:--------

    const routes: Routes = [
  {path:'',component:AdminSectionComponent,

  children:[
    { path: 'login', loadChildren: () => import('./login/login.module').then(m => m.LoginModule) },
    { path: 'signup', loadChildren: () => import('./signup/signup.module').then(m => m.SignupModule) },
    { path: 'error', loadChildren: () => import('./server-error/server-error.module').then(m => m.ServerErrorModule) },
    { path: 'access-denied', loadChildren: () => import('./access-denied/access-denied.module').then(m => m.AccessDeniedModule) },
    { path: 'not-found', loadChildren: () => import('./not-found/not-found.module').then(m => m.NotFoundModule) },
    { path: '**', redirectTo: 'not-found' }
  ]}

];

在替换为 myy 阵列路由之后,您将了解为什么没有发生路由

于 2020-04-10T13:23:15.990 回答