[英]login/logout navigation in Angular
In my menu, I have an item named Logout
, When the user clicks on Logout
, the user isn't direct to the login page but toward the portfolio page.在我的菜单中,我有一个名为
Logout
的项目,当用户单击Logout
,用户不是直接进入登录页面,而是直接进入投资组合页面。 I d'ont understand the problem.我不明白这个问题。
app-routing.module.ts app-routing.module.ts
const routes: Routes = [
{
path: '',
component: PortfolioComponent,
canActivate: [AuthGuard],
},
{
path: 'login',
component: LoginComponent,
},
{
path: 'portfolio',
component: PortfolioComponent,
},
app.component.ts app.component.ts
private createLinks() {
this.links = [
new NavigationLink(
'Sélection du portefeuille',
['portfolio'],
'fa fa-credit-card'
),
new NavigationLink(
'Corporate actions',
['corporate-action'],
'fa fa-university'
),
new NavigationLink('Valeurs', ['value'], 'fa fa-bar-chart'),
new NavigationLink('Indices Boursiers', ['indice'], 'fa fa-line-chart'),
new NavigationLink('Devises', ['devise'], 'fa fa-money'),
new NavigationLink(
'Tableau de valeurs',
['valuable-table'],
'fa fa-list-alt'
),
new NavigationLink('Logout', ['/login'], 'fa fa-circle-o-notch'),
];
}
logout() {
this.authenticationService.logout();
this.router.navigate(['/login']);
}
I can give you my code -> Stackblitz , the password is test1 .我可以给你我的代码 -> Stackblitz ,密码是test1 。
Because you're not logging out.因为你没有退出。
In navigation-side-panel.component.html
, you're ONLY routerlinking to the login page WITHOUT logging out in your auth service.在
navigation-side-panel.component.html
,您只是路由链接到登录页面,而无需注销您的身份验证服务。
In the login.component.ts
constructor, on line 27, you check if the auth service user is still valid, and navigate to ['/'].在
login.component.ts
构造函数中,在第 27 行,您检查身份验证服务用户是否仍然有效,并导航到 ['/']。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.