Skip to content

Commit

Permalink
feat(alita router wx-router): 支持 类小程序switchTab
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Nov 12, 2019
1 parent 844f815 commit 94a1600
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/路由.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ history的所有API
| popTo(key)|返回到key页|
| popToWithProps(key, newParams)|返回到key页,并设置路由参数为newParams|
| getCurrentRoutes| 获取当前路由栈|
| switchTab| 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面|

### 4. 指定入口页

Expand Down
9 changes: 9 additions & 0 deletions packages/router/src/native/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ class History {
}
}
}

switchTab(routeName) {
this.popToTop()
const navigateAction = NavigationActions.navigate({
routeName: routeName,
});

this.dispatch(navigateAction)
}
}

export default new History()
11 changes: 10 additions & 1 deletion packages/wx-router/miniprogram_dist/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,14 @@ export default history = {

}
}
}
},

switchTab(pkname, path,) {
const fpath = `${pkname}${path}`
const url = wx._historyConfig[fpath]

wx.switchTab({
url,
})
},
}
3 changes: 2 additions & 1 deletion src/basetran/handleMisc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const historyPrefixSet = new Set([
'push',
'popTo',
'popToWithProps',
'replace'
'replace',
'switchTab'
])

export default function (ast, {isFuncComp}) {
Expand Down

0 comments on commit 94a1600

Please sign in to comment.