【发布时间】:2021-12-26 14:10:55
【问题描述】:
我想构建一个简单的函数,如果 route.name 为 Idx,则将浏览器转发到特定目的地,如果不是,则重新加载页面。我使用以下代码并得到以下错误
我使用 vue 2-x。
代码
reloadPage() {
if (this.$route.name == "Idx") {
this.$router.push('/')
//console.log("test")
} else {
this.$router.go() // RELOAD THE PAGE TO OVERTAKE THE CHANGES
}
}
错误
未捕获(承诺)NavigationDuplicated:避免冗余 导航到当前位置:“/idx”。
仅当我在 /idx 站点中运行该函数时才会出现此错误。
我错过了什么?
谢谢!
【问题讨论】:
-
window.location.reload(); -
嘿亚当,谢谢,但如果我用 window.location.reload(); 替换 this.$router.go();该页面根本不会重新加载....当我将 this.$router.go() 放在一个额外的函数中时它可以工作,但这并不好看
标签: vuejs2 vue-router