i have a peculiar situation in Angular 2.0 with routing
I don't want to repeat a navigation. i.e if a user goes to page a -> then goes to page b-> then again goes to page a-> then goes to page c and when the user presses back button, the user should be redirected to page b and not page a. What i want to achieve is Pressing the back button multiple times should not display the same page more than once. So if i do a>b>c>a>c>b>a>c>b>a and then start pressing back : pages a,b,c should come only once & not based on regular browser behavior.
On successful login, if i press back button, the login screen shouldn't come, rather it should exit or something like a blank URL and not the login URL.
Any suggestions how to implement this ?
Should i use NavigationStart/NavigationEnd
& write my logic there ?
I solved the following by writting my own LocationStrategy
@Injectable()
export class TestClass implements LocationStrategy {
path(includeHash?: boolean) : string{
//write my own logic here
}
pushState(state: any, title: string, url: string, queryParams: string) : void{
console.log("push state called");
//write my own logic here
}
}
And in my app.module.ts
{provide:LocationStrategy,useClass:TestClass },
This way i was able to achieve my requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With