1

当我执行 {path: '', redirectTo: '/login', pathMatch: 'full'} 并转到 localhost:4200 时,我得到一个空白页,我不会登录。

我有我的应用程序路线。

应用路线

  export const appRoutes: Routes = [
  {
    path: 'home',
    loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
    canActivate: [AuthGuard]
  },
  {
    path: 'admin',
    loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule),
    canActivate: [AuthGuard],
    data: { permittedRoles: ["Admin"] }
  },
  {
    path: 'content',
    loadChildren: () => import('./content/content.module').then(m => m.ContentModule),
    canActivate: [AuthGuard]
  },
  {
    path: 'login',
    //loadChildren: './user/user.module#UserModule'
    loadChildren: () => import('./user/user.module').then(m => m.UserModule),
  },
  {
    path: 'settings',
    loadChildren: () => import('./settings/settings.module').then(m => m.SettingsModule),
    canActivate: [AuthGuard]

  },
  
  {
    path: '**', redirectTo: '/login'
  },
  {
    path: '', redirectTo: '/login', pathMatch: 'full'
  }
]

我有我的 userRoutes

用户路线

  export const userRoutes: Routes = [
  {
    path: '', component: UserComponent,
    children: [
      {
        path: '', component: SignInComponent
      },
      {
        path: 'signup', component: SignUpComponent
      },
      {
        path: 'resetPassword', component: ResetPasswordComponent
      },
      {
        path: 'passwordSent', component: PasswordLinkSentComponent
      },
      {
        path: 'forgotPassword', component: ForgotPasswordComponent
      },
      {
        path: 'personalDetails', component: PersonalDetailsComponent
      }
    ]
  }
]

任何人都知道似乎是什么问题?

提前谢谢大家。

4

1 回答 1

0

您可以使用 Component 属性而不是重定向

 const routes: Routes = [
      {
        path: "",
        component: LogInComponent,//Write name of component
        pathMatch: "full",     
      },
      {
        path: 'home',
        loadChildren: () => import('./home/home.module').then(m => m.HomeModule)
      },
      {
        path: 'admin',
        loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule),
        data: { permittedRoles: ["Admin"] }
      },
      {
        path: 'content',
        loadChildren: () => import('./content/content.module').then(m => m.ContentModule)    
      },
      {
        path: 'login',
        //loadChildren: './user/user.module#UserModule'
        loadChildren: () => import('./user/user.module').then(m => m.UserModule)
      },
      {
        path: 'settings',
        loadChildren: () => import('./settings/settings.module').then(m => m.SettingsModule)    
      },
       { path: "**", component: LogInComponent,pathMatch : "full"}
    ]

确保您在app-routing.module.ts中添加了这些行

@NgModule({
  imports: [
    RouterModule.forRoot(routes)
  ],
  exports: [RouterModule],
})

编辑:使用可以在模块级别激活。

于 2020-06-24T07:53:02.167 回答