In Javascript, how do I “clear” the back (history -1)?

前端 未结 3 523
忘掉有多难
忘掉有多难 2020-11-29 22:26

When the user loads the page, I immediately do a window redirect to another location.

The problem is, when the user clicks back, it\'ll go back to the page which doe

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 22:32

    For anyone coming across this page and looking for an AngularJS way to accomplish this (rather than javascript), use the $location service's replace() method (documentation) :

    Use $location.url('/newpath'); or $location.path('/newpath'); as you normally would to do the redirection in angular. And then just add $location.replace(); right after it. Or you can chain the commands like this:

    $location.url('/newpath').replace();
    

提交回复
热议问题