支付宝小程序页面跳转——openURL、navigateToAlipayPage

基础库 2.7.20 或更高版本,建议使用 my.ap.openURL 进行跳转,案例如下:

my.ap.openURL({
	url: 'https://render.alipay.com/p/404',
		success: (res) => {
		    my.showToast({
		      type: 'success',
		      content: '跳转成功',
		      duration: 3000,
		    });
		},
		fail: (err) => {
		    my.showToast({
		      type: 'exception',
		      content: '跳转失败',
		      duration: 3000,
		    });
		}
});

基础库较低的版本,如 1.25.4,openURL 跳不了,建议用 my.ap.navigateToAlipayPage 进行跳转,案例如下:

my.ap.navigateToAlipayPage({
	path: 'https://render.alipay.com/p/404',
		success: (res) => {
		    my.showToast({
		      type: 'success',
		      content: '跳转成功',
		      duration: 3000,
		    });
		},
		fail: (err) => {
		    my.showToast({
		      type: 'exception',
		      content: '跳转失败',
		      duration: 3000,
		    });
		}
});

猜你喜欢

转载自blog.csdn.net/m0_54355172/article/details/131944286