title: Taro.switchTab(option)

sidebar_label: switchTab

Redirects to the tabBar page and closes all non-tabBar pages.

Reference

Type

  1. (option: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Required Description
url string Yes Path to the tabBar page (a page to be defined in the tabBar field of app.json) to be navigated to. Parameters cannot be appended after the path.
complete (res: CallbackResult) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: CallbackResult) => void No The callback function for a failed API call
success (res: CallbackResult) => void No The callback function for a successful API call

Sample Code

  1. {
  2. "tabBar": {
  3. "list": [{
  4. "pagePath": "index",
  5. "text": "Home"
  6. },{
  7. "pagePath": "other",
  8. "text": "Other"
  9. }]
  10. }
  11. }
  1. Taro.switchTab({
  2. url: '/index'
  3. })

API Support

API WeChat Mini-Program H5 React Native
Taro.switchTab ✔️ ✔️ ✔️