UNPKG

isun

Version:

快速创建vue项目

95 lines (89 loc) 2.61 kB
import Vue from 'vue' import VueRouter from 'vue-router' // import Home from '../views/Home.vue' Vue.use(VueRouter) // 解决重复点击路由的bug const routePush = VueRouter.prototype.push VueRouter.prototype.push = function push (location) { return routePush.call(this, location).catch(err => err) } const routeReplace = VueRouter.prototype.replace VueRouter.prototype.replace = function push (location) { return routeReplace.call(this, location).catch(err => err) } const routes = [ { path: '/Login', name: 'Login', component: () => import('@/views/login/Index.vue'), meta: { title: '登录', // 中文标题 requiresAuth: false, // 无token是否跳转到登录页 keepAlive: false, // 是否缓存页面(跳转其它页面后是否还可以返回) show: true, // 是否显示 icon: '\ue63b' // 对应图标 } }, { path: '/', name: 'Home', component: () => import('@/views/Home.vue'), meta: { title: '首页', requiresAuth: true, keepAlive: true, show: true, icon: '\ue63b' }, children: [ { path: '/', name: 'About', component: () => import('@/views/main/Index.vue'), meta: { title: '首页', requiresAuth: true, keepAlive: true, show: true, icon: '\ue63b' }, children: [ ] }, { path: '/about', name: 'About', component: () => import('@/views/main/About.vue'), meta: { title: '关于我们', requiresAuth: true, keepAlive: true, show: true, icon: '\ue63b' }, children: [ ] } ] } ] const router = new VueRouter({ mode: 'history', base: process.env.BASE_URL, routes }) router.beforeEach((to, from, next) => { if (to.matched.some((r) => r.meta.requiresAuth)) { if (window.localStorage.getItem('platformToken')) { // 判断是否已经登录 next() } else { next({ path: '/Login', query: { redirect: to.fullPath } }) } } else { next() } }) export default router