• 周一. 10 月 7th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

vue动态设置路由重定向

admin

11 月 28, 2021

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' }
    }]
  },
]

发表回复