簡體   English   中英

Angular 中的登錄/注銷導航

[英]login/logout navigation in Angular

在我的菜單中,我有一個名為Logout的項目,當用戶單擊Logout ,用戶不是直接進入登錄頁面,而是直接進入投資組合頁面。 我不明白這個問題。

app-routing.module.ts

const routes: Routes = [
  {
    path: '',
    component: PortfolioComponent,
    canActivate: [AuthGuard],
  },

  {
    path: 'login',
    component: LoginComponent,
  },

  {
    path: 'portfolio',
    component: PortfolioComponent,
  },

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']);
}

我可以給你我的代碼 -> Stackblitz ,密碼是test1

因為你沒有退出。

navigation-side-panel.component.html ,您只是路由鏈接到登錄頁面,而無需注銷您的身份驗證服務。

login.component.ts構造函數中,在第 27 行,您檢查身份驗證服務用戶是否仍然有效,並導航到 ['/']。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM