javascript - 我需要使用浏览器按钮返回上一个动态页面

标签 javascript angular typescript

例如: 我在这个页面上, 密码?型号 = XS% 20Max & 屏幕 = 6.5 & 颜色 = 1 & 容量 = 64GB

点击返回我会转到此页面

密码?型号 = XS% 20Max & 屏幕 = 6.5 & 颜色 = 1

然后再次点击将返回该页面

密码?型号 = XS% 20Max & 屏幕 = 6.5

我有一个按钮可以执行此行为,但我会使用浏览器按钮。

我目前正在使用 typescript,但即使是解决方案,使用 JS 也会很好。

这是返回之前页面的 div。

back() {
    this.capacity = null;
    this.canOrder = true;
    this.accepted = false;
    this.canOrderSubsidized = true;
    $(".final_selector").fadeOut(300)
    $(".capacity_selector").delay(300).fadeIn(300)
    $(".backCapacity").fadeOut(300)
    $(".backColor").delay(300).fadeIn(300)
  }

div 生成结果,但我想使用浏览器后退按钮生成结果。

最佳答案

请阅读Angular official documentation第一的。然后您将能够使用 Angular Router 并定义每个所需的路由 (url)。

使用以下代码可以实现后退导航:

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

@Component({
  //...
})
class SomeComponent {
  constructor(private location: Location) {}

  back() {
    this.location.back();
  }
}

如上所述in this answer .

关于javascript - 我需要使用浏览器按钮返回上一个动态页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56836315/

相关文章:

javascript - 将 Bootstrap 单选按钮绑定(bind)到 Angular 属性

javascript - 删除数组中的单元格

javascript - typescript 错误? `this` `get` 语法和 `defineProperty` 的 `get` 之间的差异

angularjs - ReactiveX JS 和 TypeScript - 如何退订?

angular - Angular CLI 版本 9.1.1 的 Visual Studio CODE 中的 angular.json 错误中的 "Property Not Allowed"

json - 以 Angular 将行追加到现有数据列表

javascript - Kendo DropDownList 条件 if else 模板

javascript - 我可以在asp.net-mvc中加载带有partialView的javascript文件吗?

Angular 2模态错误

javascript - Angular Treetable (Primeng 树表) - 获取所有子节点的父节点