my.switchTab

Introduction

Jump to the specified tabBar page and close all other pages that are not tabBar.

If the Mini Program is an application of multiple tabs (tabs can be switched at the bottom of the client window), it is possible to use tabBar to configure the behavior of the specified tab, and the page to display during the tab switchover.

Note: on the page to which it jumps through the page jumping (my.navigateTo) or page redirecting (my.redirectTo, even if the page is defined in the tabBar configuration, the bottom tab bar is not displayed. In addition, the first page of the tabBar must be the home page.

Sample Code

copy
// app.json
{
  "tabBar": {
    "items": [{
      "pagePath": "page/home/index",
      "name": "Home"
    },{
      "pagePath": "page/user/index",
      "name": "User"
    }]
  }
}
copy
my.switchTab({
  url: 'page/home/index'
})

Parameters

ParameterTypeMandatoryDescription
urlStringYesPath of the jumping tabBar page (page to be defined in the tabBar field in the app.json). Note: The path cannot be followed by parameters.
successFunctionNoCallback function upon call success
failFunctionNoCallback function upon call failure
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure)

tabBar Configuration

AttributeTypeMandatoryDescription
textColorHexColorNoText color
selectedColorHexColorNoColor of highlighted text
backgroundColorHexColorNoBackground color
itemsArrayYesConfigured for each tab

Configured for each item:

AttributeTypeMandatoryDescription
pagePathStringYesSet page path
nameStringYesName
iconStringNoNormal icon path
activeIconStringNoHighlighted icon path

The recommended icon size is 60*60px. The system performs unequal stretching and scaling for any incoming picture.

Example

copy
{
  "tabBar": {
    "textColor": "#dddddd",
    "selectedColor": "#49a9ee",
    "backgroundColor": "#ffffff",
    "items": [
      {
        "pagePath": "pages/index/index",
        "name": "Home"
      },
      {
        "pagePath": "pages/logs/logs",
        "name": "Log"
      }
    ]
  }
}