Angular 8.页面刷新后如何防止路由重置

时间:2019-08-15 13:02:55

标签: angular redirect routing page-refresh

刷新页面后重置路由 这是路由器模块

const routes: Routes = [
  { path: '', component: LoginComponent },
  { path: 'login', component: LoginComponent },
  { path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
  { path: 'parameters', component: ParametersDialogComponent },
  { path: 'report1', component: Report1Component, canActivate: [AuthGuard] },
  { path: 'report2', component: Report2Component, canActivate: [AuthGuard] },
  { path: '**', redirectTo: 'login', pathMatch: 'full'}

登录

Router Event: NavigationStart
platform-browser.js:292 NavigationStart(id: 4, url: '/home')
platform-browser.js:292 NavigationStart {id: 4, url: "/home", navigationTrigger: "imperative", restoredState: null}
platform-browser.js:301 Router Event: RoutesRecognized
platform-browser.js:292 RoutesRecognized(id: 4, url: '/home', urlAfterRedirects: '/home', state: Route(url:'', path:'') { Route(url:'home', path:'home') } )

当前路由为localhost:4200 / home

刷新后我得到:

Router Event: NavigationStart
platform-browser.js:292 NavigationStart(id: 1, url: '/')
platform-browser.js:292 NavigationStart {id: 1, url: "/", navigationTrigger: "imperative", restoredState: null}

并重定向到登录页面

如何防止这种情况?

0 个答案:

没有答案