用户登录后以及按角度导航后刷新标题菜单

时间:2018-09-03 05:02:02

标签: angular typescript

我正在使用angular和JWT进行用户身份验证,效果很好。但是登录后,当我使用“ this.router.navigate(['/ blogs']);”则标题菜单不会刷新。仍然有“登录和注册”链接。

我正在将app.component中的页眉和页脚组件注入:

<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>

和路由:

export const appRoutes: Routes = [
  { path: 'home', component: HomeComponent, canActivate:[AuthGuard] },
  { path: 'blogs', component: BlogsComponent, canActivate:[AuthGuard] },
  {
    path: 'signup', component: UserComponent,
    children: [{ path: '', component: SignUpComponent }]
  },
  {
    path: 'login', component: UserComponent,
    children: [{ path: '', component: SignInComponent }]
  },
  { path: '', redirectTo: '/home', pathMatch: 'full' }

];

我还使用了服务来检查是否已登录的用户,但是它不能用于导航。当我刷新时,它工作正常。

请提出建议。

0 个答案:

没有答案
相关问题