uniapp 返回上一页

有可返回的页面则直接返回,uni.navigateBack默认返回失败之后会自动刷新页面,无法继续返回

goback() {
    
    
			// #ifdef H5
			let canBack = true;
			const pages = getCurrentPages();
			// 有可返回的页面则直接返回,uni.navigateBack默认返回失败之后会自动刷新页面 				,无法继续返回
			if (pages.length > 1) {
    
    
				uni.navigateBack(1);
				return;
			}
			// vue router 可以返回uni.navigateBack失败的页面 但是会重新加载
			let a = this.$router.go(-1);
			// router.go失败之后则重定向到首页
			if (a == undefined) {
    
    
				uni.reLaunch({
    
    
					url: '/pages/tabbar/index'
				});
			}
			return;
			// #endif
			uni.navigateBack(1);
		}

点击链接加入群聊【vue前端小白交流群】:https://jq.qq.com/?_wv=1027&k=4RfgTyec
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42386231/article/details/122555171