index.js 1.88 KB
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home.vue'

import { getXToken, configWx } from '@/utils/aCommon'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home
  },
  {
    path: '/discount',
    name: 'Discount',
    component: () => import('@/views/sideNav/discount/index')
  },
  {
    path: '/invite',
    name: 'register',
    component: () => import('@/views/sideNav/register/index')
  },
  {
    path: '/manInfo',
    name: 'ManInfo',
    component: () => import('@/views/sideNav/manInfo/index')
  },
  {
    path: '/goodPost',
    name: 'GoodPost',
    component: () => import('@/views/sideNav/goodPost/index')
  }
  
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

const whiteList = ['/discount', 'discount']

router.beforeEach((to, from ,next) => {
  // alert(`--->route: beforeEach: to =${JSON.stringify(to)}. from =${from}. next =${JSON.stringify(next)}`)
  if(whiteList.indexOf(to.path) != -1) {
    // alert(`--->route: beforeEach: If: UnIn whiteList.`)
    if(sessionStorage.getItem('zConfigWx') === 'Pass'){
      next()
    } else {
      configWx(to)
    }

  } else {
    // alert(`--->route: beforeEach: If: In whiteList.`)

    next()
  }

  // if (whiteList.indexOf(to.path) !== -1) {
  //   next()
  // } else {
  //   if(sessionStorage.getItem('unionid')) {
  //     next()
  //   } else {
  //     getUnionId(to)
  //     // next()
  //   }
  // }
})

// async function getUnionId (to) {
//   await getXToken()
//   configWx(to)
// }

export default router