My goal is to automatically navigate to a specific website when a certain condition for the URL is met.
Consider the following scenario in the ngOnInit()
method of app.component.ts
:
if (urlMatchesCondition()) {
await this.router.navigateByUrl('special-site');
} else {
await this.router.initialNavigation();
}
When logging the ActivatedRoute
(
await this.route.url.pipe(take(1)).toPromise()
) and Router
(this.router.url
), an empty route or "/" respectively is displayed.
For instance, if I wanted to check if the route contains "test", how could I achieve that?