vue-learn/src/router/router.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-06-16 02:20:06 +00:00
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login'
2020-06-16 07:20:27 +00:00
import Home from '../components/Home'
2020-06-17 03:01:34 +00:00
import welcome from '../components/welcome'
2020-06-17 10:04:40 +00:00
import users from '../components/users/users'
2020-06-22 03:37:05 +00:00
import access from '../components/access/access'
import roles from '../components/access/roles'
import categories from '../components/goods/categories'
2020-06-16 07:20:27 +00:00
2020-06-16 02:20:06 +00:00
Vue.use(VueRouter)
const routes = [
2020-06-17 10:04:40 +00:00
{ path: '/', redirect: '/login' },
{ path: '/login', component: Login },
2020-06-16 07:20:27 +00:00
{
path: '/home',
2020-06-17 03:01:34 +00:00
component: Home,
redirect: '/welcome',
children: [
2020-06-17 10:04:40 +00:00
{ path: '/welcome', component: welcome },
2020-06-22 03:37:05 +00:00
{ path: '/users', component: users },
{ path: '/rights', component: access },
{ path: '/roles', component: roles },
{ path: '/categories', component: categories }
2020-06-17 03:01:34 +00:00
]
2020-06-16 02:20:06 +00:00
}
]
const router = new VueRouter({
routes
})
2020-06-16 07:28:53 +00:00
router.beforeEach((to, from, next) => {
if (to.path === '/login') {
return next()
}
const token = sessionStorage.getItem('token')
if (!token) {
return next('/login')
}
next()
})
2020-06-16 02:20:06 +00:00
export default router