javascript - Go Back in Angular 6 when skiplocationchange is true - Stack Overflow

Routing in Angular 6When i route to a particular location i navigate with route.navigate(['home&#

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/mon';

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

  constructor(private _location: Location) 
  {}

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

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/mon';

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

  constructor(private _location: Location) 
  {}

  backClicked() {
    this._location.back();
  }
}
Share Improve this question asked Nov 15, 2018 at 12:56 Parshuram KalvikatteParshuram Kalvikatte 1,6464 gold badges23 silver badges45 bronze badges 2
  • Have you found how to hide url and at the same time be able to go back in Angular? I need it too. :) – manymanymore Commented May 19, 2020 at 20:27
  • 1 No @YaroslavTrofimov I wrote a service which saves my url history and push and pop base on Forward and Backward – Parshuram Kalvikatte Commented Jun 8, 2020 at 7:02
Add a ment  | 

2 Answers 2

Reset to default 5

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.

you can pass dynamic data to a Route The option to pass the dynamic data or a user-defined object was added in the Angular Version +8 using the state object. The state object is stored in History API

Using routerLink directive

<a [routerLink]="['antherUrl']" [state]="{ id:1 , name:'currentUrl'}">Dynamic Data</a>

Using navigateByUrl

this.router.navigateByUrl('/antherUrl', { state: { id:1 , name:'currentUrl' } });

Accessing the state value The state can be accessed by using the getCurrentNavigation method of the router (works only in the constructor)

 perviousUrl = this.router.getCurrentNavigation().extras.state


goBack() {
 this.router.navigate([this.previousUrl.name],{skipLocationChange: true});
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744400758a4572373.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信