Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 注销时router.navigate和breadcrumb之间发生冲突_Angular_Authentication_Local Storage_Logout - Fatal编程技术网

Angular 注销时router.navigate和breadcrumb之间发生冲突

Angular 注销时router.navigate和breadcrumb之间发生冲突,angular,authentication,local-storage,logout,Angular,Authentication,Local Storage,Logout,当我注销时,authToken将从本地存储中删除,但我在控制台中收到一条消息,表明我已重定向到面包屑,当我再次登录时,当我导航时,控制台中会显示两次组件 面包屑有问题。router.navigate(['/login']) 哪些部件?你能把路由器的路由添加到问题中吗?我自己解决了这个问题。原因是我在仪表板中多次订阅了一个事件。每次初始化组件时,都会创建一个新的订阅服务器。我的解决方案:使用Ngondestory,只需使用unsubscribe:)取消订阅即可。哪些组件?你能把路由器的路由添加到问

当我注销时,authToken将从本地存储中删除,但我在控制台中收到一条消息,表明我已重定向到面包屑,当我再次登录时,当我导航时,控制台中会显示两次组件

面包屑有问题。router.navigate(['/login'])


哪些部件?你能把路由器的
路由添加到问题中吗?我自己解决了这个问题。原因是我在仪表板中多次订阅了一个事件。每次初始化组件时,都会创建一个新的订阅服务器。我的解决方案:使用Ngondestory,只需使用unsubscribe:)取消订阅即可。哪些组件?你能把路由器的
路由添加到问题中吗?我自己解决了这个问题。原因是我在仪表板中多次订阅了一个事件。每次初始化组件时,都会创建一个新的订阅服务器。我的解决方案:使用Ngondestory,只需使用unsubscribe:)取消订阅即可
// To logout
  logout() {
    localStorage.removeItem('currentUser');
    this.router.navigate(['/login']);
  }

// Breadcrum problem

  this.router.events
      .pipe(filter(event => event instanceof NavigationEnd))
      .pipe(map(() => this.route))
      .pipe(map((route) => {
        while (route.firstChild) { route = route.firstChild; }
        return route;
      }))
      .pipe(filter(route => route.outlet === PRIMARY_OUTLET))
      .subscribe(route => {

        const snapshot = this.router.routerState.snapshot;
        this.breadcrumbs = [];
        const url = snapshot.url;
        const routeData = route.snapshot.data;

        console.log(routeData);
        const label = routeData.breadcrumb;
        const params = snapshot.root.params;

        this.breadcrumbs.push({
          url,
          label,
          params
        });

      });