Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
  }
}
like image 205
Parshuram Kalvikatte Avatar asked Nov 14 '25 10:11

Parshuram Kalvikatte


1 Answers

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.

like image 77
Teddy Sterne Avatar answered Nov 17 '25 05:11

Teddy Sterne