import Vue from 'vue'
import Router from 'vue-router'

const routerPush = Router.prototype.push

Router.prototype.push = function push(location) {

	// if(typeof(location)=="string"){
	//   var Separator = "&";
	//   if(location.indexOf('?')==-1) { Separator='?'; }
	//   location = location + Separator + "random=" + Math.random();
	// }

	return routerPush.call(this, location).catch(error => error)
}

Vue.use(Router)

let router = new Router({
	// mode: 'history',
	base: process.env.BASE_URL,
	routes: [{
			path: '/',
			redirect: '/login'
		},
		{
			path: '/login',
			name: 'login',
			component: () => import('./views/Login.vue'),
			meta: {
				title: '登录'
			}
		},
		{
			path: '/home',
			name: 'home',
			component: () => import('./views/Home.vue'),
			redirect: '/home/regList',
			meta: {
				title: ''
			},
			children: [{
					path: 'regList',
					name: 'regList',
					component: () => import('./views/home/regList.vue'),
					meta: {
						title: '注册码列表'
					}
				},
				{
					path: 'buyReg',
					name: 'buyReg',
					component: () => import('./views/home/buyReg.vue'),
					meta: {
						title: '购买注册码'
					}
				},
				{
					path: 'abonementList',
					name: 'abonementList',
					component: () => import('./views/home/abonementList.vue'),
					meta: {
						title: '用户列表'
					}
				},
				{
					path: 'orderList',
					name: 'orderList',
					component: () => import('./views/home/orderList.vue'),
					meta: {
						title: '订单列表'
					}
				},
				{
					path: 'addressList',
					name: 'addressList',
					component: () => import('./views/home/addressList.vue'),
					meta: {
						title: '地址列表'
					}
				},
				{
					path: 'rechangeList',
					name: 'rechangeList',
					component: () => import('./views/home/rechangeList.vue'),
					meta: {
						title: '充值记录'
					}
				},
				{
					path: 'rechange',
					name: 'rechange',
					component: () => import('./views/home/rechange.vue'),
					meta: {
						title: '充值'
					}
				},
				{
					path: 'taking',
					name: 'taking',
					component: () => import('./views/home/taking.vue'),
					meta: {
						title: '提现'
					}
				},
				{
					path: 'takingList',
					name: 'takingList',
					component: () => import('./views/home/takingList.vue'),
					meta: {
						title: '提现记录'
					}
				},
				{
					path: 'transferList',
					name: 'transferList',
					component: () => import('./views/home/transferList.vue'),
					meta: {
						title: '转账记录'
					}
				},
				{
					path: 'transfer',
					name: 'transferList',
					component: () => import('./views/home/transfer.vue'),
					meta: {
						title: '转账'
					}
				},
				{
					path: 'setAgent',
					name: 'setAgent',
					component: () => import('./views/home/setAgent.vue'),
					meta: {
						title: '设置下级代理'
					}
				},
				{
					path: 'statistics',
					name: 'statistics',
					component: () => import('./views/home/statistics.vue'),
					meta: {
						title: '统计'
					}
				},
			]
		},
		{
			path: '*',
			redirect: '/home'
		}
	]
})

// 路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  // if (!tokenStr) return next('/login')
  next()
})

export default router