Search code examples
javascripthtmlangularroutesangular6

Go Back in Angular 6 when skiplocationchange is true


Routing in Angular 6

When i route to a particular location i navigate with

route.navigate(['/home'], { skipLocationChange: true });

but when returning back to previous route the below code is not helping, Is there any another way or should by remove "{ skipLocationChange: true }"

import {Component} from '@angular/core';
import {Location} from '@angular/common';

@Component({
  // component's declarations here
})
class SomeComponent {

  constructor(private _location: Location) 
  {}

  backClicked() {
    this._location.back();
  }
}

Solution

  • Using skipLocationChange

    Navigates without pushing a new state into history.

    This is why using location.back() will not work as it simply moves the browser back to the previous state in the history. And the current state is unchanged even though the url in the browser was modified.

    You should not use skipLocationChange if you want the next state of the page to be added to the browser's history.