index.js 4.1 KB
import Vue from 'vue'
import Router from 'vue-router'

import Login from './../pages/Login.vue'
import NotFound from './../pages/404.vue'
import Home from './../pages/Home.vue'
import Main from './../pages/Main.vue'

// import Table from './../pages/nav1/Table.vue'
// import Form from './../pages/nav1/Form.vue'
// import user from './../pages/nav1/user.vue'
// import Page4 from './../pages/nav2/Page4.vue'
// import Page5 from './../pages/nav2/Page5.vue'
import Page6 from './../pages/nav3/Page6.vue'

import Dashboard from './../pages/dashboard/Dashboard.vue'
import VideoManager from './../pages/video-manager/VideoManager.vue'
import BannerManager from './../pages/classroom/BannerManager.vue'
import ArticleManager from './../pages/classroom/ArticleManager.vue'
import TagManager from './../pages/classroom/TagManager.vue'
import StoreManager from './../pages/store-manager/StoreManager.vue'

Vue.use(Router)

const router = new Router({
  routes: [{
      path: '/login',
      component: Login,
      name: '',
      hidden: true
    },
    {
      path: '/404',
      component: NotFound,
      name: '',
      hidden: true
    },
    //{ path: '/main', component: Main },
    {
      path: '/',
      component: Home,
      name: '',
      iconCls: 'fa fa-address-card',
      leaf: true, //只有一个节点
      children: [{
        path: '/',
        component: Dashboard,
        name: 'Dashboard'
      }]
    },
    {
      path: '/',
      component: Home,
      name: '',
      iconCls: 'fa fa-address-card',
      leaf: true, //只有一个节点
      children: [{
        path: '/video/manager',
        component: VideoManager,
        name: '视频管理'
      }]
    },
    {
      path: '/',
      component: Home,
      name: '爸妈学堂',
      iconCls: 'fa fa-id-card-o',
      children: [{
          path: '/tag/manager',
          component: TagManager,
          name: '话题管理'
        },
        {
          path: '/banner/manager',
          component: BannerManager,
          name: '头图管理'
        },
        {
          path: '/article/manager',
          component: ArticleManager,
          name: '文章管理'
        }
      ]
    },
    {
      path: '/',
      component: Home,
      name: '',
      iconCls: 'fa fa-address-card',
      leaf: true, //只有一个节点
      children: [{
        path: '/store/manager',
        component: StoreManager,
        name: '呵护到家'
      }]
    },
    // {
    //   path: '/',
    //   component: Home,
    //   name: '导航一',
    //   iconCls: 'el-icon-message', //图标样式class
    //   children: [{
    //       path: '/main',
    //       component: Main,
    //       name: '主页',
    //       hidden: true
    //     },
    //     {
    //       path: '/table',
    //       component: Table,
    //       name: 'Table'
    //     },
    //     {
    //       path: '/form',
    //       component: Form,
    //       name: 'Form'
    //     },
    //     {
    //       path: '/user',
    //       component: user,
    //       name: '列表'
    //     },
    //   ]
    // },
    // {
    //   path: '/',
    //   component: Home,
    //   name: '导航二',
    //   iconCls: 'fa fa-id-card-o',
    //   children: [{
    //       path: '/page4',
    //       component: Page4,
    //       name: '页面4'
    //     },
    //     {
    //       path: '/page5',
    //       component: Page5,
    //       name: '页面5'
    //     }
    //   ]
    // },
    // {
    //   path: '/',
    //   component: Home,
    //   name: '',
    //   iconCls: 'fa fa-address-card',
    //   leaf: true, //只有一个节点
    //   children: [{
    //     path: '/page6',
    //     component: Page6,
    //     name: '导航三'
    //   }]
    // },

    {
      path: '*',
      hidden: true,
      redirect: {
        path: '/404'
      }
    }
  ]
})


router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({
      path: '/login'
    })
  } else {
    next()
  }
})

export default router;