【问题标题】:Angular 6 router not working on chrome/IEAngular 6 路由器不适用于 chrome/IE
【发布时间】:2019-01-09 13:08:11
【问题描述】:

我正在使用 Angular 6 来重定向用户。登录成功后,用户重定向到主页。相同的代码在 Firefox(52.8.1 版)上完美运行,但 chrome 不会重定向到子 url。

我的路由代码是:

const routes: Routes = [
  {
    path: 'login',
    component: LoginComponent,
  },
  {
    path: '',
    redirectTo: 'dashboard/home',
    pathMatch: 'full',
    canActivate: [LoggedInGuard]
  },
  {
    path: 'dashboard',
    component: DashboardComponent,
    pathMatch: 'prefix',
    canActivate: [LoggedInGuard],
    children: [
      {path: 'InfoManage', component: InfoManageComponent},
      {path: 'home',component: HomeComponent}
    ]
  },
  // All Other Routes Goto Login *****************************************/
  {path: '**', redirectTo: '/login'}
];

当 blank("") url 出现时,firefox 重定向到 /dashboard/home 但 chrome 仅重定向到 /dashboard。这是角度错误还是我错过了什么?

【问题讨论】:

  • 它确实看起来像一个错误,如果我是你有重定向到 dashboard 并且在仪表板路由中,当没有指定仪表板后的路由时重定向到主页

标签: javascript angular spring-boot angular6


【解决方案1】:

我认为是路由优先级的问题,而不是 Chrome 的问题。

const routes: Routes = [
  {
    path: 'login',
    component: LoginComponent,
  },
  {
    path: '',
    redirectTo: 'dashboard',
    pathMatch: 'full',
    canActivate: [LoggedInGuard]
  },
  {
    path: 'dashboard',
    component: DashboardComponent,
    canActivate: [LoggedInGuard],
    children: [
      {path: '',component: HomeComponent},
      {path: 'InfoManage', component: InfoManageComponent}
    ]
  },
  // All Other Routes Goto Login *****************************************/
  {path: '**', redirectTo: '/login'}
];

对于空的 '' 路由,尝试直接重定向 'dashboard' 而不是处理大小写。我希望它有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-19
    • 2017-06-24
    • 1970-01-01
    • 2022-12-28
    • 2014-07-07
    • 2019-02-12
    • 2019-04-08
    • 2017-01-25
    相关资源
    最近更新 更多