您现在的位置是: 首页 > 前端开发 > Vue Vue 路由跳转错误 NavigationDuplicated: Avoided redundant navigation to current location
Vue 路由跳转错误 NavigationDuplicated: Avoided redundant navigation to current location
2020-09-17 【Vue】 5268人已围观 9204次浏览
简介Vue 路由跳转错误 NavigationDuplicated: Avoided redundant navigation to current location
Vue 中通过 $router.push 进行页面跳转时,出现错误提示
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler (Promise/async): "NavigationDuplicated: Avoided redundant navigation to current location: "/"."
found in
---> <Header> at src/components/Header.vue
<Home> at src/views/Home.vue
<App> at src/App.vue
<Root>
warn @ vue.runtime.esm.js?2b0e:619
logError @ vue.runtime.esm.js?2b0e:1884
globalHandleError @ vue.runtime.esm.js?2b0e:1879
handleError @ vue.runtime.esm.js?2b0e:1839
eval @ vue.runtime.esm.js?2b0e:1856
Promise.catch (async)
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1856
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
vue.runtime.esm.js?2b0e:1888 NavigationDuplicated: Avoided redundant navigation to current location: "/".
at createRouterError (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:1959:15)
at createNavigationDuplicatedError (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:1929:15)
at HashHistory.confirmTransition (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2223:18)
at HashHistory.transitionTo (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2153:8)
at HashHistory.push (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2623:10)
at eval (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2951:22)
at new Promise (<anonymous>)
at VueRouter.push (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2950:12)
at click (eval at ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"126c737d-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/Header.vue?vue&type=template&id=61dd7a3d&scoped=true& (http://localhost:8080/static/js/app.js:1151:1), <anonymous>:27:34)
at invokeWithErrorHandling (webpack-internal:///./node_modules/vue/dist/vue.runtime.esm.js:1853:26)
里面关键的信息就是 "NavigationDuplicated: Avoided redundant navigation to current location: "/"."
出现此类错误主要原因就是因为 $router.push 跳转时,与当前地址相同
解决方法就是在 router 文件夹下的 index.js 中加入下面的代码
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
完整代码就是
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(VueRouter)
// 解决 NavigationDuplicated: Avoided redundant navigation to current location 报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
const routes = [
{
......
很赞哦! (0)
相关文章
点击排行
- Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR DISABLE You can't write or read against a disable instance
- Debian apt 使用国内镜像
- RocketMQ 出现 sendDefaultImpl call timeout 问题
- 类 BASE64Decoder 程序包 sun.misc 找不到符号
- SpringBoot @NotBlank 不生效问题
- 记一次 Mybatis-Plus 自动填充无效问题解决
- SpringBoot 2.x 文件上传出现 The field file exceeds its maximum permitted size of 1048576 bytes
- nuxt 项目完整部署方案
站长推荐
猜你喜欢
- 解决Lost connection to MySQL server at 'reading initial communication packet' 的方法
- Python自动生成和安装requirements.txt文件中的依赖
- win10 cmd下运行python命令弹出windows应用商店问题
- 防止Time Machine备份Parallels Desktop的虚拟硬盘文件
- ThinkPHP 解决跨域访问问题
- Laravel Dingo/api 出现 The version given was unknown or has no registered routes.报错
- SpringBoot 2.x Security security.basic.enabled=false 失效问题解决
- docker mysql 导入 SQL 脚本
- Vue 监听回车 el-input 和 input 使用方法不同
- Android SDK版本号与API级别的对照表