有没有办法避免错误:避免冗余导航到当前位置。我需要做一个分页,这是方法:
handlePageChange(page: number): void {
const query = {
...this.$route.query,
page: page.toString(),
};
this.$router.push({ name: 'PageName', query });
}
而且我不断在控制台中收到错误消息:
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/page-path?page=2".
我试着用路由器做一个捕获,但那不起作用。有人可以帮我阐明我在这里做错了什么吗? :/
最佳答案
如果忽略是安全的,并且你正在使用 vue-router ^3.4.0
,你可以这样做:
import VueRouter from 'vue-router'
const { isNavigationFailure, NavigationFailureType } = VueRouter
...
this.$router.push(fullPath).catch(error => {
if (!isNavigationFailure(error, NavigationFailureType.duplicated)) {
throw Error(error)
}
})
更多详情请引用Navigation Failures .
关于javascript - Vue Router推送错误: Avoided redundant navigation to current location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65878999/