我有一个应用程序,可以导航到一个无法前进的页面。想象一下,单击电视指南中的某个节目以打开包含该节目详细信息的页面,显然您会想要返回到电视指南。
对于返回电视指南的按钮,我有一个<a>
tag.
最建议的用例是:
- Using
href="/guide"
or
- Using
(click)=goBack()
函数调用的地方location.back()
您应该使用 Angular 的内置位置服务。
角度位置 https://angular.io/api/common/Location#back
import {Component} from '@angular/core';
import {Location} from '@angular/common';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
class AppComponent {
constructor(private location: Location) {
}
back() {
this.location.back();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)