import Vue from 'vue'
import VueRouter from 'vue-router'

//公共
import routesCar from './car'
//访客
import routesMerchant from './merchant'

if (!window.VueRouter) Vue.use(VueRouter)

const routesIndex = [
	//首页
	{
		path: '/',
		name: 'Home',
		component: () => import('../views/Home.vue'),
		meta: {
			requireAuth: false,
			role: [],
			title: '首页',
		}
	},
	//支付宝微信获取中间页
	{
		path: '/auth',
		name: 'Auth',
		component: () => import('../views/Auth.vue'),
		meta: {
			requireAuth: false,
			role: [],
			title: '支付宝微信获取中间页',
		}
	},
]

const routes = routesIndex.concat(routesCar, routesMerchant);

const router = new VueRouter({
	//base: process.env.BASE_URL,
	routes,

	// keep-alive 返回缓存页面后记录浏览位置
	scrollBehavior(to, from, savedPosition) {
		if (savedPosition) {
			return savedPosition;
		} else {
			return {
				x: 0,
				y: 0
			}
		}
	},
})

export default router
