Fork me on GitHub

vue动态设置路由重定向

router.js:

import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Login from '@/views/login/index'


export const asyncRoutes = [
   {
    path: '/',
    component: Layout,
    redirect: to=>{
      console.log('重定向了')
      console.log(store.state.user)
      if(store.state.user.name=='editor2'){
        //评论管理
        return '/discuss/index'
      }else if(store.state.user.name=='editor'){
         //用户权限管理
         return '/tree/index'
      }else{
        //内容用户权限管理
        return '/dashboard'
      }
    },
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '内容发布管理', icon: 'dashboard' }
    }]
  },
]

 

posted @ 2021-07-19 14:45  小白不白10  阅读(1215)  评论(0编辑  收藏  举报