javascript - 当 skiplocationchange 为真时返回 Angular 6

标签 javascript html angular routes angular6

Angular 6 中的路由

当我路由到一个特定位置时,我会使用

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

但是当返回到之前的路线时,下面的代码没有帮助, 有没有其他方法或应该删除“{ 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();
  }
}

最佳答案

使用 skipLocationChange

Navigates without pushing a new state into history.

这就是为什么使用 location.back() 不起作用的原因,因为它只是将浏览器移回历史记录中的先前状态。即使修改了浏览器中的 url,当前状态也没有改变。

如果您希望将页面的下一个状态添加到浏览器的历史记录中,则不应使用 skipLocationChange

关于javascript - 当 skiplocationchange 为真时返回 Angular 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53319987/

相关文章:

javascript - 使用 JS 或 jQuery 按字母顺序排列列表

javascript - 如何使用 AJAX 发送单独的表单数据以进行回复?

javascript - 如何在 Angular 2 中使用 ELementRef 或 @ViewChild 访问特定的 DOM 元素?

CSS :before on inline SVG

css - Angular - 将自定义CSS应用于无效的FormControl,而不是FormGroup?

angular - 什么时候使用 Angular 2 工厂函数?

javascript - HTML 错误无法设置 null 属性(匿名函数)

javascript - AngularJS UI 路由器在工厂/服务中使用已解析的依赖项

javascript - 这些 ActiveXObject 和 XMLHttpRequest 检查是否适用于 IE6 以外的任何其他浏览器?

javascript - 如何测试上下文菜单是否打开或显示?