Skip to content

Commit 94a1600

Browse files
committed
feat(alita router wx-router): 支持 类小程序switchTab
1 parent 844f815 commit 94a1600

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

docs/路由.md

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ history的所有API
8989
| popTo(key)|返回到key页|
9090
| popToWithProps(key, newParams)|返回到key页,并设置路由参数为newParams|
9191
| getCurrentRoutes| 获取当前路由栈|
92+
| switchTab| 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面|
9293

9394
### 4. 指定入口页
9495

packages/router/src/native/history.js

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ class History {
109109
}
110110
}
111111
}
112+
113+
switchTab(routeName) {
114+
this.popToTop()
115+
const navigateAction = NavigationActions.navigate({
116+
routeName: routeName,
117+
});
118+
119+
this.dispatch(navigateAction)
120+
}
112121
}
113122

114123
export default new History()

packages/wx-router/miniprogram_dist/history.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,14 @@ export default history = {
105105

106106
}
107107
}
108-
}
108+
},
109+
110+
switchTab(pkname, path,) {
111+
const fpath = `${pkname}${path}`
112+
const url = wx._historyConfig[fpath]
113+
114+
wx.switchTab({
115+
url,
116+
})
117+
},
109118
}

src/basetran/handleMisc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const historyPrefixSet = new Set([
1414
'push',
1515
'popTo',
1616
'popToWithProps',
17-
'replace'
17+
'replace',
18+
'switchTab'
1819
])
1920

2021
export default function (ast, {isFuncComp}) {

0 commit comments

Comments
 (0)