javascript - Vue:NavigationDuplicated:避免了对当前位置的冗余导航,但需要重新加载页面
问题描述
我有这个Hashtag.vue对象:
<template>
<div v-on:click="clicked">
<div
class="tag rounded-full p-2 ">
{{text}}</div>
</div>
</template>
<script>
export default {
props: {
text: {
type: String
},
date: {
type: String
},
link: {
type: String,
}
},
created() {
console.log("this link: " + this.link);
},
methods: {
clicked() {
this.$router.push({
path: this.getTo
})
}
},
computed: {
getTo: function() {
console.log("text: " + this.text);
console.log("link: " + "hashtag/" + this.text);
return "/hashtag/" + this.text;
}
}
}
</script>
当它被点击时,它需要去
http://localhost:8080/hashtag/text
它去那里并显示带有此主题标签的文章。
这些文章还包含其他主题标签。但是当我在那个页面上并点击其他一些标签时,我得到了
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/hashtag/no".
错误。页面上的文章保持不变(对于旧主题标签)。
如何让它重新加载页面?
截至目前,页面上的文章/hashtag/text
是这样加载的:
export default {
components: {ArticleList},
created() {
console.log("getAllArticles method");
const response = ArticleService.getArticlesByTag(this.$route.params.tag).then((response) => {
console.log("articles res: " + JSON.stringify(response));
this.articles = response.data.articles;
console.log("changed articles: " + JSON.stringify(this.articles));
})
},
data() {
return {
articles: []
}
}
}
解决方案
一种解决方法是向路由查询添加时间戳
methods: {
clicked() {
this.$router.push({
path: this.getTo,
query: { timestamp: Date.now() } // changes every time when clicked called
})
}
},
推荐阅读
- ios - 如何根据内容在主容器视图中添加高度?和其他东西
- r - 如何根据分位数信息编写输入为向量输出为字符向量的函数
- highcharts - 如何在highcharts的甘特图中用特定颜色填充条形之间的空白?
- java - Jmockit如何匹配类的“任何”参数类型
克拉兹 - jquery - AJAX POST 响应中的某些字符串为空
- html - 如何在元数据中实现 Schema.org 属性?
- bash - Bash 脚本比较和运行命令
- php - 使用流明发送电子邮件,而不在 env 文件中设置 smtp 凭据
- ios - iOS 上的多个 L2CAP 通道 (rdar://46227689)
- reactjs - redux 商店替代品与定制商店反应