browser forward and backward button in angular event

I am new to angular 4 using typescript, how can we differentiate forward and backward button in the browser. this.subscription = PopStateEvent) => { console.log("Localtion Back", x); // // Handler });

how to come out of the application stack:usecase assume user started with then user type . In, user will navigate a>b>c>d>e then from e page navigate to b and if the user press browser
back button first time it should navigate to a and second time back button press it should come back to