如何导航到以前的状态并返回浏览器历史记录.
我记得AngularJS支持这个:
$window.history.back();
React支持这个:
import { browserHistory } from 'react-router' browserHistory.goBack();
如何在Angular 2> = v2.1.0中返回和以前的浏览器历史记录
解决方法
您可以使用内置的位置服务,它具有后备api.
示例代码 –
import {Component} from '@angular/core'; import {Location} from '@angular/common'; @Component({ .... }) class AppComponent { constructor(private _location: Location) { } backClicked() { this._location.back(); } }
参考:https://angular.io/docs/ts/latest/api/common/index/Location-class.html
看看这是否有帮助.