I have an angular application deployed to www.mydomain.com/myapp
From Main page I have route to another page www.mydomain.com/myapp/page2
I have an external website and I want to link to www.mydomain.com/myapp/page2. When user clicks on the link, it goes to www.mydomain.com/myapp/homepage instead.
How to resolve this?
1
From the external page try put an URL with a query parameter for the page to indicate whether to redirect to homepage or not:
www.mydomain.com/myapp/page2?fromExternal=true.
Then in your page2 component, write a code to check whether the query parameter exist, if so, redirect to homepage.
constructor(
private route: ActivatedRoute,
private router: Router,
) {}
ngOnInit() {
this.route.queryParams.subscribe(params => {
if (params.fromExternal) {
this.router.redirect(['/homepage'])
}
});
}