82 lines
1.6 KiB
JavaScript
82 lines
1.6 KiB
JavaScript
|
/*
|
||
|
* @Author: gtz
|
||
|
* @Date: 2022-07-25 14:18:00
|
||
|
* @LastEditors: gtz
|
||
|
* @LastEditTime: 2022-07-25 15:12:22
|
||
|
* @Description: file content
|
||
|
* @FilePath: \xbapp\src\router\index.js
|
||
|
*/
|
||
|
import Vue from 'vue'
|
||
|
import Router from 'vue-router'
|
||
|
import login from '@/pages/common/login'
|
||
|
import notFound from '@/pages/common/404'
|
||
|
import index from '@/pages/index/index'
|
||
|
import eqInspection from '@/pages/eqInspection/eqInspection'
|
||
|
import material from '@/pages/material/material'
|
||
|
|
||
|
Vue.use(Router)
|
||
|
|
||
|
const router = new Router({
|
||
|
routes: [
|
||
|
{
|
||
|
path: '/',
|
||
|
name: 'login',
|
||
|
component: login
|
||
|
},
|
||
|
{
|
||
|
path: '/index',
|
||
|
name: 'index',
|
||
|
meta: {requireAuth: true},
|
||
|
component: index
|
||
|
},
|
||
|
{
|
||
|
path: '/eqInspection',
|
||
|
name: 'eqInspection',
|
||
|
meta: {requireAuth: true},
|
||
|
component: eqInspection
|
||
|
},
|
||
|
{
|
||
|
path: '/material',
|
||
|
name: 'material',
|
||
|
meta: {requireAuth: true},
|
||
|
component: material
|
||
|
},
|
||
|
{
|
||
|
path: '/404',
|
||
|
name: 'notFound',
|
||
|
component: notFound
|
||
|
},
|
||
|
{
|
||
|
path: '*',
|
||
|
redirect: '/404'
|
||
|
}
|
||
|
]
|
||
|
})
|
||
|
|
||
|
Router.prototype.goBack = function () {
|
||
|
this.isBack = true
|
||
|
window.history.go(-1)
|
||
|
}
|
||
|
|
||
|
const valid = () => {
|
||
|
return sessionStorage.getItem('userInfo')
|
||
|
}
|
||
|
|
||
|
router.beforeResolve((to, from, next) => {
|
||
|
if (to.matched.some(record => record.meta.requireAuth)) {
|
||
|
// this route requires auth, check if logged in
|
||
|
// if not, redirect to login page.
|
||
|
if (valid()) {
|
||
|
next()
|
||
|
} else {
|
||
|
next({
|
||
|
path: '/'
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
next() // 确保一定要调用 next()
|
||
|
}
|
||
|
})
|
||
|
|
||
|
export default router
|