美文网首页
vue项目中路由出现message:"Navigating to

vue项目中路由出现message:"Navigating to

作者: hwj6820 | 来源:发表于2019-10-21 14:40 被阅读0次

    在vue项目中路由出现message:"Navigating to current location(xxx) is not allowed "的问题

    原因:在路由中添加了相同的路由。

    解决:

    重写路由的push方法

    在src/router/index.js 里面import Router from 'vue-router'下面写入下面方法即可

    /**

    * 重写路由的push方法

    */

    const routerPush = Router.prototype.push

    Router.prototype.push = functionpush(location){

      return routerPush.call(this, location).catch(error=> error)

    }

    vue相同路由跳转强制刷新该路由组件

    1.在菜单的路由跳转上绑定一个随机query参数,例如时间戳或者随机数:

    this.$router.push({

        path:"/xxx",

        query:{

            t:Date.now(),

        },

    });

    2.在路由容器上绑定key值:

    <router-view :key="$route.path + $route.query.t">

    相关文章

      网友评论

          本文标题:vue项目中路由出现message:"Navigating to

          本文链接:https://www.haomeiwen.com/subject/cxetvctx.html