我有代码可以替换浏览器地址栏中的 url。在替换 url 之前,会显示一条警告以指示更改。单击警报对话框后,url 将变回原始地址。如何从 angularjs Controller 更改地址栏中的 url,以便更改持续存在?
这是我的尝试:
$scope.goToDashboard = function () {
window.history.replaceState("data", "Dashboard", "/dashboard");
// on reaching here the url bar is /dashboard and on clicking it, it returns to the previous url
alert("here...2");
$scope.show = true;
}
如何用新字符串永久重写 url?
最佳答案
上述解决方案应该可行,但如果您正在考虑让 Angular 事情顺利进行,您可能需要手动运行摘要摘要循环。
相反,我建议您使用 $location
API 以 Angular 方式执行此操作。
$location.url('/dashboard').replace();
关于javascript - 从 angularjs Controller 替换 url 栏中的现有 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53157759/