index.js 1.88 KB
Newer Older
xulili's avatar
xulili committed
1 2 3 4
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home.vue'

Z's avatar
Z committed
5 6
import { getXToken, configWx } from '@/utils/aCommon'

xulili's avatar
xulili committed
7 8 9 10 11 12 13 14
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home
  },
15 16 17
  {
    path: '/discount',
    name: 'Discount',
xd's avatar
xd committed
18
    component: () => import('@/views/sideNav/discount/index')
19
  },
xulili's avatar
xulili committed
20
  {
xulili's avatar
xulili committed
21
    path: '/invite',
xulili's avatar
xulili committed
22 23 24
    name: 'register',
    component: () => import('@/views/sideNav/register/index')
  },
25 26 27 28 29 30 31 32 33
  {
    path: '/manInfo',
    name: 'ManInfo',
    component: () => import('@/views/sideNav/manInfo/index')
  },
  {
    path: '/goodPost',
    name: 'GoodPost',
    component: () => import('@/views/sideNav/goodPost/index')
xd's avatar
xd committed
34 35
  }
  
xulili's avatar
xulili committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  // {
  //   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
})

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

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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()
  //   }
  // }
})
Z's avatar
Z committed
81 82 83 84 85 86

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

xulili's avatar
xulili committed
87
export default router