import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) const routes = [ { path: '/', name: 'home', component: () => import('../views/home.vue') }, { path: '/page/:id', name: 'page', component: () => import('../views/page.vue'), props: true }, { path: '/list/:id', name: 'list', component: () => import('../views/list.vue'), props: true }, { path: '/details/:id', name: 'details', component: () => import('../views/details.vue'), props: true } ] const router = new VueRouter({ mode: 'history', // base: process.env.BASE_URL, routes }) router.beforeEach((to, from, next) => { // if (to.path === from.path) return // // 此处判断登录状态 失效则退回登录页 清空登录状态 // const token = sessionStorage.getItem('token') // if (!token && !/\/login$/.test(to.path)) { // next('/login') // } next() }) export default router