0
votes

I have 2 models: AppModule, PanelModule.

in my AppComponent, I check if the user is logged in, and if he is, I redirect him to the panel. This is how I do this:

ngOnInit() {
      //If he is alredy logged, redirect him to the panel
      this.authService.login().subscribe(() => {
          this.authService.loaded = true;
      if (this.authService.isLoggedIn) {
          console.log("Navigating to panel..");
        this.router.navigate(['/panel']);
      }
    });
  }

The problem starts when my location is a child route. for example:

/panel/users

If I'm trying to access the URL directly, I navigate back to the /panel because the user is logged in and this.router.navigate(['/panel']); is executed.

What's the right approach so my app will redirect the user to the right path?

1

1 Answers

0
votes

You probably only want to subscribe to the first result:

this.authService.login().first().subscribe(() => {