navigator大于 10 层后,自动 redirect
-
问:请问一下,现在想要修改navigator组件的跳转逻辑,当达到最大的10层之后,自动变成redirect模式,这个有办法可以做到吗?
答:如下,// 处理微信跳转超过10层 function jumpUrl (url, options = {}) { const pages = Taro.getCurrentPages() let method = options.method || 'navigateTo' if (url && typeof url === 'string') { if (method == 'navigateTo' && pages.length >= PAGE_LEVEL_LIMIT - 3) { method = 'redirectTo' } if (method == 'navigateToByForce') { method = 'navigateTo' } if (method == 'navigateTo' && pages.length == PAGE_LEVEL_LIMIT) { method = 'redirectTo' } Taro[method]({ url }) } }
-
用全局数据去计数啊,或者本地缓存
-
@Joker 不错哦,学习了