Angular 登录页面

标签 angular authentication sticky

我是 Angular 新手。我一直在 YouTube 上观看教程,所有教程都教如何使用粘性导航栏进行路由。是否可以单击链接并导航到没有导航栏的全新页面?

This is the index.html displaying. The blue words are navigation and are routed.

我正在尝试路由到登录页面而不显示导航栏。可以这样做吗?

Here is the code for the index.html and the app.component.html just in case its necessary

最佳答案

是的,可以导航到登录页面,但导航栏不会显示在该登录页面中。

实现此目的的一种方法是,当当前路线为 /login 时,从 View 中删除导航栏。在 app.component.ts 中创建一个 bool 属性,该属性将表示路由的当前状态是否为 /login

app.component.ts 可能如下所示:

    import { Component } from '@angular/core';
    import { Router, NavigationEnd } from '@angular/router';
    import { filter } from 'rxjs/operators'; 

    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css'],
    })
    export class AppComponent {

      isLoginPage: boolean;

      constructor(private router: Router) {
        this.router.events.pipe(
          filter(event => event instanceof NavigationEnd)
        ).subscribe((event: NavigationEnd) => {
          this.isLoginPage = this.router.url === '/login';
        });
      }
    }

然后使用 *ngIf 指令将此 bool 属性绑定(bind)到导航栏。

在app.component.html中:

    <div *ngIf="!isLoginPage" id="temporary-navigator style="text-align: center;">
      ... 
    </div>

关于 Angular 登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62095354/

相关文章:

ios - cordova ios 中的基本身份验证失败

css - 粘性表格标题在 Angular Material mat-sidenav-container 中不起作用

javascript - GET api 在 chrome 上工作正常,但在 IE11 上不行

javascript - 在 chartJS 和 Angular 上水平滚动时使 y 轴变粘

javascript - 更改检测在 Angular 2 的指令事件输出中不起作用

c++ - 是否有粘性操纵器的官方资源

cvs - 有没有办法删除 CVS 中的所有粘性选项?

angular - 将代码从 ChangeDetectionStrategy.Default 重构为 ChangeDetectionStrategy.OnPush

authentication - 为什么我无法连接到 ssh 反向隧道?

php - isset($_SESSION ['admin' ]) 是一种危险的授予访问权限的方式吗?