wwl
2025-02-15 5b4e348267b5541d54fffcc75c7b307ad514a692
src/router/index.js
@@ -1,6 +1,6 @@
import Vue from 'vue'
import Router from 'vue-router'
import Cookies from "js-cookie";
Vue.use(Router)
/* Layout */
@@ -405,8 +405,26 @@
  return routerPush.call(this, location).catch(err => err)
}
export default new Router({
const router = new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
router.beforeEach((to, from, next) => {
  if (from.path === '/login') {
    // 获取当前环境
    const env = process.env.VUE_APP_ENV
    // 生产环境处理
    if (env === 'production') {
      // 防止用户通过地址栏直接输入URL访问
      if (from.name === null && to.path !== window.location.pathname) {
        next(false)
        return
      }
    }
  }
  next()
})
export default router