一、前言

小程序中页面栈最多十层,随着页面增加路由跳转很容易在不知道的情况下就会堆栈到十层,再用navigateTo去跳转就跳不动了。

这时候就需要删除当前页面栈(redirectTo)或删除所有页面栈(reLaunch)来跳转了。页面栈可以通过getCurrentPages方法获取。

1、新建js

navigateRoute.js

function navigateTo(url) {  if (getCurrentPages().length = 10) {    wx.redirectTo({      url: url,      success: function (res) { },      fail: function (res) { },      complete: function (res) { },    })  } else {    wx.navigateTo({      url: url,    })  }}module.exports = navigateTo

2、js引用

import navigateTo from "../../utils/navigateRoute.js"navigateTo('/pages/public/postDetail/postDetail?id=' + e.currentTarget.dataset.id)

 

TAG标签: 微信小程序微信交易限制怎么解除

http://www.xiaochengxub.com/read-102527.html