vue路由

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

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容