简体   繁体   English

Angular 中的登录/注销导航

[英]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.

相关问题 在同一页面上使用 angular 登录和注销 - login and logout with angular on the same page Angular(5)-成功登录后,登录按钮未更改为注销 - Angular(5) - Login button not changing to Logout on successful login angular 中用于登录和注销的导航栏选项中的简单显示隐藏功能。 我想知道为什么它不起作用 - Simple show hide functionality in the navigation bar options for login and logout in angular. I want to know why it's not working Angular 8 菜单中的用户登录/注销按钮未更新 - User login/logout button in menu Angular 8 not updating 仅在Angular 7中登录后启用注销按钮 - enable Logout button only after Login in Angular 7 无法在登录和注销时更改侧菜单-Angular Ionic - unable to change sidemenu on Login and Logout - Angular Ionic 身份服务器:在 Angular 中登录和注销后重定向? - Identity Server: Redirect after login and logout in Angular? 在 angular 应用程序中注销后重定向到登录页面 - Redirect to login page after logout in angular app 登录/注销时Angular 2 Typescript重新加载组件 - Angular 2 Typescript reload components on login/logout Angular 注销后 MSAL 重定向到 Microsoft 登录 - Angular MSAL Redirect to Microsoft Login after Logout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM