首页 > 解决方案 > 用户登录后和角度导航后刷新标题菜单

问题描述

我正在使用 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' }

];

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

请建议。

标签: angulartypescript

解决方案


推荐阅读