// import Home from "@/pages/Home";
// import Login from "@/pages/Login";
// import Register from "@/pages/Register";
// import Search from "@/pages/Search";

// 为了解决首屏加载慢,默认一进去就会获取全部数据,用到了路由懒加载
// 原理是:将路由对应的组件打包成一个个代码块,只有在路由被访问的时候,路由对应的组件才会被加载
const Home = () => import("@/pages/Home")
const Login = () => import("@/pages/Login")
const Register = () => import("@/pages/Register")
const Search = () => import("@/pages/Search")
const Detail = () => import("@/pages/Detail")
const AddCartSuccess = () => import("@/pages/AddCartSuccess")
const ShopCart = () => import("@/pages/ShopCart")
const Trade = () => import("@/pages/Trade")
const Pay = () => import("@/pages/Pay")
const PaySuccess = () => import("@/pages/PaySuccess")
const Center = () => import("@/pages/Center")
// 引入二级路由组件
const myOrder = () => import("@/pages/Center/myOrder")
const groupOrder = () => import("@/pages/Center/groupOrder")

export default [
	// meta是路由元信息,每个组件可以通过this.$route获取到当前路由的信息,用到最多就是
	// 根据meta路由元信息上的数据动态展示组件,有些路由组件不想展示,有的想展示,
	// 相当于v-if和v-show
	// 添加name属性的原因是:简化路由跳转的时候携带hash地址
	// path不能够有大写
	{ path: "/", redirect: "/home" },
	{ path: "/home", component: Home, meta: { show: true } },
	{ path: "/login", component: Login, meta: { show: false } },
	{ path: "/register", component: Register, meta: { show: false } },
	{
		path: "/search/:keyword?",
		component: Search,
		meta: { show: true },
		props: true,
		name: "search",
	},
	{ path: "/detail/:detailid", component: Detail, meta: { show: true }, name: "detail" },
	{ path: "/addcartsuccess", name: "addcartsuccess", component: AddCartSuccess, meta: { show: true } },
	{ path: "/shopCart", name: "shopCart", component: ShopCart, meta: { show: true } },
	{
		path: "/trade",
		name: "trade",
		component: Trade,
		meta: { show: true },
		beforeEnter: (to, from, next) => {
			// 去trade必须从shopCart而来
			if (from.path == '/shopCart') {
				next()
			} else {
				// 其他路由访问trade,停留在当前
				next(false)
			}
		}
	},
	{
		path: "/pay",
		name: "pay",
		component: Pay,
		meta: { show: true },
		beforeEnter: (to, from, next) => {
			if (from.path == '/trade') {
				next()
			} else {
				// 其他路由访问trade,停留在当前
				next(false)
			}
		}
	},
	{
		path: "/paySuccess",
		name: "paySuccess",
		component: PaySuccess,
		meta: { show: true }
	},
	{
		path: "/center", name: "center", component: Center, meta: { show: true },
		redirect: '/center/myOrder',
		// 二级路由组件
		children: [
			{ path: 'myOrder', component: myOrder },
			{ path: 'groupOrder', component: groupOrder }
		]
	}
]