«

登录状态

emer 发布于 2018-12-4 16:35   2163 次阅读     


import Vue from 'vue'
import Router from 'vue-router'
import Login from './components/login/index.vue'
import Index from './components/index/index.vue'
import Home from './views/Home.vue'
import ChangePass from './views/nav1/user.vue'
import Table from './views/nav1/Table.vue'
import Main from './views/index.vue'
import store from './store/index'
Vue.use(Router)

const router= new Router({
  routes: [
     {
      path: '/',
      name: '',
      meta:{
        title:"首页"
      },
      component: Main,
      hidden: true 
    },
    {
      path: '/login',
      name: 'login',
      meta:{
        title:"登录页面"
      },
      component: Login,
      hidden: true 
    },
    // {
    //   path:"/index",
    //   name:"index",
    //   meta:{
    //     title:"后台管理"
    //   },
    //   component:Index,
    //   hidden: true 
    //   },
      {
      path:"/index",
      name:"上传管理",
      meta:{
        title:"后台管理",
        auth:true
      },
      component:Home,
      iconCls: 'el-icon-upload',//图标样式class
        children: [
           { path: '/index', component:Index, name: '上传', meta:{title:"后台管理"}},
            { path: '/index/piclist', component:Table, name: '上传列表', meta:{title:"后台管理"}},

        ]
      },
      {
      path:"/pass",
      name:"密码管理",
      meta:{
        title:"后台管理",
        auth:true
      },
      component:Home,
      iconCls: 'el-icon-edit',//图标样式class
        children: [
          { path: '/pass', component:ChangePass, name: '修改密码', meta:{title:"后台管理"}}

        ]
      }
  ]
});
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  if(to.matched.some(m=>m.meta.auth)){
      if(store.state.login.isLogin==1){
          next();
      }else{
        next({path:"/login",query:{rurl:to.fullPath}});
      }

  }else{
      next();
  }

})
export default router