You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
855 B
47 lines
855 B
/*
|
|
* @Author: 付刚
|
|
* @Date: 2020-12-15 09:41:20
|
|
* @LastEditors: 付刚
|
|
* @LastEditTime: 2021-07-22 11:36:46
|
|
* @FilePath: \LujiachangfangPhone\src\router.js
|
|
*/
|
|
import Vue from 'vue'
|
|
import Router from 'vue-router'
|
|
import Login from './views/Login.vue'
|
|
import Home from './views/Home.vue'
|
|
|
|
Vue.use(Router)
|
|
|
|
const router = new Router({
|
|
base: process.env.BASE_URL,
|
|
routes: [
|
|
{
|
|
path: '/',
|
|
name: '登录页',
|
|
component: Login
|
|
},
|
|
{
|
|
path: '/home',
|
|
name: '地图首页',
|
|
component: Home
|
|
}
|
|
]
|
|
})
|
|
|
|
// 路由拦截
|
|
router.beforeEach((to, from, next) => {
|
|
let token = localStorage.getItem('lj_token')
|
|
if (token) {
|
|
next()
|
|
} else {
|
|
if (to.name === '登录页') {
|
|
next()
|
|
} else {
|
|
// 没有登录,返回登录页
|
|
router.replace('/')
|
|
}
|
|
}
|
|
})
|
|
|
|
export default router
|