diff --git "a/docs/\350\267\257\347\224\261.md" "b/docs/\350\267\257\347\224\261.md" index 94b94f4..c9f5f5c 100644 --- "a/docs/\350\267\257\347\224\261.md" +++ "b/docs/\350\267\257\347\224\261.md" @@ -89,6 +89,7 @@ history的所有API | popTo(key)|返回到key页| | popToWithProps(key, newParams)|返回到key页,并设置路由参数为newParams| | getCurrentRoutes| 获取当前路由栈| +| switchTab| 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面| ### 4. 指定入口页 diff --git a/packages/router/src/native/history.js b/packages/router/src/native/history.js index b17903f..6eba09a 100644 --- a/packages/router/src/native/history.js +++ b/packages/router/src/native/history.js @@ -109,6 +109,15 @@ class History { } } } + + switchTab(routeName) { + this.popToTop() + const navigateAction = NavigationActions.navigate({ + routeName: routeName, + }); + + this.dispatch(navigateAction) + } } export default new History() \ No newline at end of file diff --git a/packages/wx-router/miniprogram_dist/history.js b/packages/wx-router/miniprogram_dist/history.js index dbade13..f952831 100644 --- a/packages/wx-router/miniprogram_dist/history.js +++ b/packages/wx-router/miniprogram_dist/history.js @@ -105,5 +105,14 @@ export default history = { } } - } + }, + + switchTab(pkname, path,) { + const fpath = `${pkname}${path}` + const url = wx._historyConfig[fpath] + + wx.switchTab({ + url, + }) + }, } diff --git a/src/basetran/handleMisc.js b/src/basetran/handleMisc.js index 5f7e398..970feb5 100644 --- a/src/basetran/handleMisc.js +++ b/src/basetran/handleMisc.js @@ -14,7 +14,8 @@ const historyPrefixSet = new Set([ 'push', 'popTo', 'popToWithProps', - 'replace' + 'replace', + 'switchTab' ]) export default function (ast, {isFuncComp}) {