import pageUrl from './pageUrl'

function navTo(obj) {
	let token = '';
	if(process.env.UNI_PLATFORM =="h5"){
		if(window.location.href.indexOf('//casedata.igandan.com')>-1){
			token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
		}else{
			token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
		}
	}else{
		  const { envVersion } = uni.getAccountInfoSync().miniProgram;
          if (envVersion == "release") {
			token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
		  }else{
			token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
		  }
	}
	if (!token) {
		let page_url = pageUrl();
		uni.setStorageSync('redirectUrl', page_url);
		uni.navigateTo({
			url: '/pages/login/login?redirectUrl=has'
		});
	} else {
		if(process.env.UNI_PLATFORM =="h5"){
				uni.navigateTo(obj)
		}else{
			const pages = getCurrentPages();
		let len = pages.length;
		console.log(len)
		if (len >=10) {
			uni.redirectTo(obj)
		} else {
			uni.navigateTo(obj)
			
		}
		}
	}
	

}

export default navTo