angular 11不在订阅内导航

angular 11不在订阅内导航,angular,angular-router,msal.js,Angular,Angular Router,Msal.js,问题是我无法重定向(URL更改内容不会更改) 但是这个代码是有效的,为什么? router.navigateByUrl(“/activate”)在订阅之外 ngOnInit(): void { const self = this; this.router.navigateByUrl('/activate'); this.activatedRoute.queryParams.subscribe(params => { if (this.authS

问题是我无法重定向(URL更改内容不会更改)

但是这个代码是有效的,为什么? router.navigateByUrl(“/activate”)在订阅之外

ngOnInit(): void {
    const self = this;
    
    this.router.navigateByUrl('/activate');
    this.activatedRoute.queryParams.subscribe(params => {
      if (this.authService.instance.getActiveAccount() != null) {
        let redirectUrl = params['redirectUrl'];
        if(redirectUrl !== undefined) {
          self.router.navigateByUrl('/activate');
          return true; 
        }
      }
    });
  }

我真的需要重定向URL,而不是现在硬编码的这个.authService.instance.getActiveAccount()在做什么?您能否确认您的代码正在通过此条件?这是否返回了一个需要订阅的可观察对象?@Edward是的,我在返回true时设置了一个断点;
ngOnInit(): void {
    const self = this;
    
    this.router.navigateByUrl('/activate');
    this.activatedRoute.queryParams.subscribe(params => {
      if (this.authService.instance.getActiveAccount() != null) {
        let redirectUrl = params['redirectUrl'];
        if(redirectUrl !== undefined) {
          self.router.navigateByUrl('/activate');
          return true; 
        }
      }
    });
  }