I want to call a certain function after a user logs in. The user may log in from any page and on a successful log in, the user is redirected back to the previous page that they were browsing.
I'm using Router.navigate for redirecting to the page.
After looking for a while NavigationEnd seems like an option which would work, but it applies to all router events, not just a specific one.
My login.component.ts has something like this:
// ...
this.authenticationService.login(this.credentials)
.pipe(first())
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
// Need to call a function `doSomething()` here.
},
error => {
// Implement error handling
});
// ...
I know that it's not a promise but I'm looking for something like:
this.router.navigate([this.returnUrl])
.then(this.doSomething()); // or .pipe()