VUEJS删除添加的路由或清除添加的路由

时间:2018-06-04 08:30:34

标签: vue.js

每个人的好日子,

我试图删除vuejs上的addedRoutes ..在对vue-router文档进行了几个小时的研究之后,我找不到可以清除addedRoutes的方法。

这是我的代码:

new Vue({
  el: '#app',
  render: h => h(App),
  router:router,
  data(){
      return{
          isAuth:null
      }
  },
  created(){

        this.checkAuthentication();
        if(this.isAuth){
            this.getUserRole();
        }
        bus.$on('reload', (passData) => {
            this.getUserRole();
            if(this.isAuth){
               this.getUserRole();
            }
        });
  },
  methods:{
      getUserRole(){
          this.$http.get('api/users/getRole').then(response => {
              console.log(response);
              if(response.body.is_admin){
                router.addRoutes(Routes);
              }else if(response.body.is_buh){
                router.addRoutes(BUHRoutes);
              }else if(response.body.is_so) {

              }
          });
      },
      checkAuthentication(){
          this.isAuth = this.$auth.isAuthenticated();
      }
  }
});

我的情况是,当我登录时,如果成功,我会获得userRole,并根据该用户角色,我根据userRole添加路由router.addRoutes()。但是,当我退出时,我在控制台日志[vue-router] Duplicate named routes definition: { name: "division-maintenance", path: "/division-maintenance" }上收到此警告。这就是为什么我正在研究如何清除addRoutes。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我用vue-route创建一个示例文件

import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'

Vue.use(Router)

export default new Router({
  base: process.env.BASE_URL, //config url base
  routes: [
    {
      path: '/home',
      name: 'home',
      component: Home
    },
  ],
  mode: 'history'
})

属性mode: 'history'删除了#

相关问题