96 lines
2.0 KiB
JavaScript
96 lines
2.0 KiB
JavaScript
/*
|
|
* @Author: gtz
|
|
* @Date: 2022-07-25 14:18:00
|
|
* @LastEditors: gtz
|
|
* @LastEditTime: 2022-07-29 13:24:07
|
|
* @Description: file content
|
|
* @FilePath: \hf-pda\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 eqInspectionAdd from '@/pages/eqInspection/eqInspection-add'
|
|
import eqInspectionEdit from '@/pages/eqInspection/eqInspection-edit'
|
|
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: '/eqInspection-add',
|
|
name: 'eqInspectionAdd',
|
|
meta: {requireAuth: true},
|
|
component: eqInspectionAdd
|
|
},
|
|
{
|
|
path: '/eqInspection-edit',
|
|
name: 'eqInspectionEdit',
|
|
meta: {requireAuth: true},
|
|
component: eqInspectionEdit
|
|
},
|
|
{
|
|
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
|