import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) const routes = [ { path: '/login', name: 'Login', component: () => import('@/views/login/index.vue'), meta: { title: '登录', noLayout: true } }, { path: '/', component: () => import('@/layout/index.vue'), redirect: '/dashboard', children: [ { path: 'dashboard', name: 'Dashboard', component: () => import('@/views/dashboard/index.vue'), meta: { title: '工作台', icon: 'el-icon-s-home' } }, { path: 'booking', name: 'Booking', component: () => import('@/views/booking/index.vue'), meta: { title: '新建预约', icon: 'el-icon-date' } }, { path: 'orders', name: 'Orders', component: () => import('@/views/orders/index.vue'), meta: { title: '开单记录', icon: 'el-icon-document' } }, { path: 'members', name: 'Members', component: () => import('@/views/members/index.vue'), meta: { title: '会员管理', icon: 'el-icon-user' } } ] } ] const router = new VueRouter({ mode: 'hash', base: process.env.BASE_URL, routes }) const whiteList = ['/login'] router.beforeEach((to, from, next) => { document.title = to.meta.title ? `${to.meta.title} - 绿纤门店` : '绿纤门店' const token = localStorage.getItem('store_token') if (token) { if (to.path === '/login') { next({ path: '/' }) } else { next() } } else { if (whiteList.includes(to.path)) { next() } else { next('/login') } } }) export default router