派生自 wuyushui/SewerAndRainNetwork

XingChuan
2021-05-31 5d3cafca01c6ad878d51533b955b530e12f9d99a
src/router/index.js
@@ -1,10 +1,11 @@
import Vue from 'vue'
import Router from 'vue-router'
import { routes } from './routes'
import { getToken } from '@/utils/navigation'
import 'nprogress/nprogress.css'
const appConfig = require('@/app.config')
const { routeMode } = appConfig
const { homeRouterName, loginRouteName, routeMode } = appConfig
const LOGIN_PAGE_ROUTE_NAME = loginRouteName
Vue.use(Router)
const baseName = process.env.NODE_ENV === 'production' ? `/${appConfig.projectName}/` : '/'
const router = new Router({
@@ -17,12 +18,37 @@
    cancel()
  })
  Vue.prototype.$cancels = []
  const token = getToken()
  if (!token && to.name !== LOGIN_PAGE_ROUTE_NAME) {
    // 未登录且要跳转的页面不是登录页
    /* next({
      name: LOGIN_PAGE_ROUTE_NAME // 跳转到登录页
    }) */
    next() // 跳转
  } else if (!token && to.name === LOGIN_PAGE_ROUTE_NAME) {
    // 未登陆且要跳转的页面是登录页
    next() // 跳转
  } else if (token && to.name === LOGIN_PAGE_ROUTE_NAME) {
    // 已登录且要跳转的页面是登录页
    // next({
    //   name: homeRouterName // 跳转到homeName页
    // })
    console.log(homeRouterName)
    next()
  } else if (!token) {
    // next({
    //   name: LOGIN_PAGE_ROUTE_NAME // 跳转到登录页
    // })
    console.log(LOGIN_PAGE_ROUTE_NAME)
    next()
  } else {
    next()
  }
  // 不需要登录认证的路由
  if (Object.hasOwnProperty.call(to.meta, 'noLoginIdentify') && to.meta.noLoginIdentify) {
    next()
    return
  }
  next()
  // next()
})
router.beforeResolve((to, from, next) => {
  next()