title: How to update previous page URL in Angular
body: <p><strong>Question:</strong> How to remove previous route <code>url</code> from history so that browser "<strong>back</strong>" button skip it?</p>
  
  <p>In my application if data is invalid or other issues - <code>Angular</code> performs redirection to error page. But if to press <strong>"Back"</strong> button in browser - user gets redirected to error page again and from there to error page. So it is kind of endless cycle.</p>
  
  <p>The idea is to remove previous <code>url</code> (with invalid data) from history so previous redirect would lead to the page before <code>url</code> with invalid data.</p>
  
  <p>We have some <code>browser.location</code> api in vanilla <code>JS</code>, but how to do that by <code>Angular</code> way?</p>
  
  <p><strong>Update:</strong> there are many ways to get previous url, like: <a href="https://stackoverflow.com/questions/41038970/how-to-determine-previous-page-url-in-angular">How to determine previous page URL in Angular?</a>. But how to set it?</p>
  
  <p><strong>Solution:</strong> I've tried to use <code>Angular</code> <code>Location.replaceState()</code> to override 
  history. In some reason it just removed one history entry without replacing it: <a href="https://angular.io/api/common/Location#replaceState" rel="nofollow noreferrer">https://angular.io/api/common/Location#replaceState</a>
  Similar behavior was in <code>vanilla JS</code> <code>History.replaceState()</code>:
  <a href="https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState</a></p>
  
  <p>I end up with changing design to use <code>skipLocationChange: true</code> in <code>NavigationExtras</code>:
  <a href="https://angular.io/api/router/NavigationExtras" rel="nofollow noreferrer">https://angular.io/api/router/NavigationExtras</a>
  so Bálint Réthy's answer fits best.</p>