import uniCrazyRouter from "uni-crazy-router";

export function setupRouter (app) {
    // 接收vue3的实例，并注册uni-crazy-router
    app.use(uniCrazyRouter)
}

const whiteList = ['pages/login/login'];
// const whiteList = [];

uniCrazyRouter.beforeEach(async (to, from ,next)=>{
	console.log('beforEach router')
	
	const path = to.url;
	const uInfo = uni.getStorageSync('uInfo') || null;
	
	if (whiteList.includes(path)) {
		next();
		return;
	}
	
	if (uInfo) {
		next();
		return;
	}
	
	uniCrazyRouter.afterNotNext(() => {
		uni.navigateTo({url: '/pages/login/login'})
		// if (uInfo) {
		// 	uni.navigateTo({url: '/pages/index/index'})
		// } else {
		// 	uni.navigateTo({url: '/pages/login/login'})
		// }
	})
})

uniCrazyRouter.afterEach((to, from)=>{
	console.log('afterEach router')
  // 逻辑代码
})

uniCrazyRouter['on'+'Error']((to, from)=>{
  
})