3

I want to clear browser navigation history in angular2 so that after user get navigated to particular page (page of my interest) the shouldn't be able to go back or forward by clicking browser back or next button.......

For now I tried importing Angular2 Location like this

 import {Location} from "angular2/router";

and using it like this to prevent navigation

 this._location.replaceState('/'); //clear browser navigation history and reset it to root /
 this._router.navigateByUrl('/home');

Note: assume Location and Router are properly injected

But its not working.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Jorin
  • 1,316
  • 1
  • 12
  • 16

1 Answers1

0

It doesn't look like this is supported by the browser. See JS - window.history - Delete a state

There was an issue created recently to allow to pass a custom HistoryStrategy that should allow you to manage how and when an URL is pushed to the history.

See also https://github.com/angular/angular/issues/3481

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • thanks... I realized that i had to implement my own custom HistoryStrategy by injecting window object and implementing window.onpopstate event... thanks will do it latter... – Jorin Mar 08 '16 at 10:16