import Vue from 'vue';
import Router from 'vue-router';
import home from '_/index/home';
import index from '_/index/index';
Vue.use(Router)
const Route = [
{
path: '/', // 首页页面
name: 'home',
component: home,
redirect: '/home/index',
children: [
{
path: '/home/index', // 企u首页页面
name: 'index',
component: index
},
{
path: '/home/companyProfile', // 企业详情
name: 'companyProfile',
// eslint-disable-next-line no-undef
component: resolve => require(['~/home/companyProfile'], resolve)
},
]
},
// 配置路由
const router = new Router({
mode: 'hash',
history: false,
routes: Route,
scrollBehavior(to, from, savedPosition) {//页面滚动的位置
return { x: 0, y: 0 }
}
});
// 全局守卫 控制用户未登录状况下的加载
// router.beforeEach((to, from, next) => {
// if (to.matched.some(res => res.meta.requireLogin)) { // 判斷是否需要登錄
// // 判断是否有登录凭证,如果有,正常跳转,没有返回登录页面或主页,并提示
// if (window.sessionStorage.getItem('token')) {
// // 根据登录时间设置过期时间 8小时
// let loginTime = parseInt(window.sessionStorage.getItem('tokenTime')) + 1000 * 60 * 8;
// let nowTime = (new Date()).getTime(); // 获取当前时间
// if (nowTime < loginTime) {
// next()
// } else {
// // Token 超时
// Message({
// showClose: true,
// message: '登录状态信息过期,请重新登陆!',
// type: 'error'
// });
// window.sessionStorage.clear();
// next({
// path: '/home/index'
// })
// }
// } else {
// // 没有登录则跳转到登录页
// next({
// path: '/home/login'
// })
// }
// } else {
// next()
// }
// });
export default router