I have a web app that was partly migrated from PHP and angular-js to angular(currently v13)
after a successful login, there's a redirection to other pages.
since my login page is angular-based, I'd like to use angular routing to redirect to pages that are angular-based and are working under the router-outlet
. And redirect using window.location
for old pages (e.g PHP).
The url to redirect to is dynamic. Is there a way that I can determine if the url is part of the angular application and can be navigated to using the router?
CodePudding user response:
You can use router events for that. Do this code in a service or your root navigation component:
constructor(private router: Router) {
router.events.pipe(
filter(event => event instanceof NavigationError),
takeUntil(this.destroy),
).subscribe(.. here you should redirect with window.location);
}
Also if you needn't error in the console, just provide custom error handler in providers:
providers: [{
provide: ErrorHandler,
useClass: CustomErrorHandler,
}],
And one last moment: you have to remove '**'
path parsing from your root routes in RouterModule
.