【发布时间】:2025-12-11 13:10:01
【问题描述】:
我有一个带有“返回”按钮的表单。当用户按下后退按钮时,脚本会转到上一页:
import { Location } from '@angular/common';
// In a place in La Mancha, whose name I do not want to remember...
this.location.back();
但是,当用户直接在地址栏中输入 url 时会发生什么?在这些情况下,应用程序会返回浏览器的主页。我想要这样的东西:
import { Location } from '@angular/common';
// In a place in La Mancha, whose name I do not want to remember...
if (this.location.history.length > 0) {
this.location.back();
} else {
this.router.navigate(['/home');
}
这可能吗?
【问题讨论】:
标签: angular typescript location back