angular - 用户登录后和角度导航后刷新标题菜单
问题描述
我正在使用 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' }
];
我还使用服务来检查用户是否登录,但它不适用于导航。当我刷新时,它工作正常。
请建议。
解决方案
推荐阅读
- python - QTableWidgetItem 做一个,停止编辑的动作
- scala - 如何从 Scala 中的 HDFS 本地读取文本文件(不使用 Spark)?
- python-3.x - 为什么在导入自己的模块时会出现回溯错误?
- php - 在 laravel 中选择查询
- c# - 在 using 语句之外声明资源
- swift - 带有换行和动态高度的 SwiftUI HStack
- typescript - Typescript 枚举实例类型
- vue.js - Vuex Action Handler Context Object 和 Payload ESLint 规则问题
- python-3.x - 在 Hello World 烧瓶应用程序中,Flask 找不到该应用程序
- ios - 自定义表格视图单元格上的附件详细信息按钮⇒内存泄漏