Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API navigation


May 19, 2021 WeChat Mini Program Development Document


Table of contents


In order to meet everyone's query needs, we collected and organized a: WeChat small program navigation, you can easily by sweeping QR code to use these small programs.

wx.navigateTo(OBJECT)

Keep the current page, jump to a page within the app, and wx.navigateBack return to the original page.

OBJECT parameter description:

Parameters Type Required Description
Url String Is The path to an in-app non-tabBar page that needs to be jumped, and the path can be followed by parameters. U se ? between the argument and ? Separated, the parameter = keys are connected & with the parameter values, and the different parameters are separated by the value of the parameters, such as 'path?key=value=value=key2?value2'
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

wx.navigateTo({
  url: 'test?id=1'
})
//test.js
Page({
  onLoad: function(option){
    console.log(option.query)
  }
})

Note: In order not to let users bother with small programs, we specify that the page path can only be five layers, please try to avoid multi-level interaction.


wx.redirectTo(OBJECT)

Close the current page and jump to a page within the app.

OBJECT parameter description:

Parameters Type Required Description
Url String Is The path of a non-tabBar page within the app that needs to be jumped, and the path can be followed by parameters. U se ? between the argument and ? Separated, the parameter = keys are connected & with the parameter values, and the different parameters are separated by the value of the parameters, such as 'path?key=value=value=key2?value2'
success Function no Interface call successful callback function
fail Function no Interface call failed callback function
complete Function no The callback function ended in the interface call (the call is successful, failed)

Sample code:

wx.redirectTo({
  url: 'test?id=1'
})

wx.reLaunch(OBJECT)

Base library version 1.1.0 starts to support, and low versions need to be compatible

Close all pages and open a page within the app.

OBJECT parameter description:

Parameters Type Required Description
Url String Is The path to an in-app non-tabBar page that needs to be jumped, and the path can be followed by parameters. U se ? between the argument and ? Separated, the parameter = keys are connected & to the parameter values with , and different parameters are separated by , such as 'path?key=value2=value2', and if the jumped page path is a tabBar page, no parameters can be taken
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

wx.reLaunch({
  url: 'test?id=1'
})
//test.js
Page({
  onLoad: function(option){
    console.log(option.query)
  }
})

wx.switchTab(OBJECT)

Jump to the tabBar page and close all other non-tabBar pages

OBJECT parameter description:

Parameters Type Required Description
Url String Is The path to the tabBar page that needs to be jumped (the page defined in app.json's tabBar field) cannot be followed by parameters
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

{
  "tabBar": {
    "list": [{
      "pagePath": "index",
      "text": "首页"
    },{
      "pagePath": "other",
      "text": "其他"
    }]
  }
}
wx.switchTab({
  url: '/index'
})

wx.navigateBack(OBJECT)

Close the current page and return to the last or multi-level page. You getCurrentPages() and decide how many layers you need to go back to.

OBJECT parameter description:

Parameters Type The default Description
delta Number 1 The number of pages returned, if delta is greater than the number of existing pages, is returned to the first page.

Example code:

// 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码

// 此处是A页面
wx.navigateTo({
  url: 'B?id=1'
})

// 此处是B页面
wx.navigateTo({
  url: 'C?id=1'
})

// 在C页面内 navigateBack,将返回A页面
wx.navigateBack({
  delta: 2
})

Tip

  1. tip : wx.navigateTo and wx.redirectTo do not allow jumps to the tabbar page, only to the tabbar page with wx.switchTab

wx.showNavigationBarLoading(Object object)

The navigation bar load animation is displayed on the current page

OBJECT parameter description:

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

wx.setNavigationBarTitle(Object object)

Dynamically set the title of the current page

OBJECT parameter description:

Property Type The default Required Description
title string Is The title of the page
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The sample code

wx.setNavigationBarTitle({
  title: '当前页面'
})

wx.setNavigationBarColor(Object object)

Base library 1.4.0 starts to support, and low versions need to be compatible.

Set the color of the page navigation bar

OBJECT parameter description:

Property Type The default Required Description
frontColor string Is Foreground color values, including buttons, titles, and status bar colors, support only #ffffff and #000000
backgroundColor string Is Background color value, the effective value is hete sixteen-color
animation Object Whether Animated effects
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The structure of object.animation

Property Type The default Required Description
duration number 0 Whether Animation change time, unit ms
timingFunc string 'linear' Whether How the animation changes

The legal value of object.animation.timingFunc

Value Description The lowest version
'linear' The speed of the animation is the same from start to finish
'easeIn' The animation starts at a low speed
'easeOut' The animation ends at a low speed
'easeInOut' The animation starts and ends at a low speed

The sample code


wx.setNavigationBarColor({
  frontColor: '#ffffff',
  backgroundColor: '#ff0000',
  animation: {
    duration: 400,
    timingFunc: 'easeIn'
  }
})

wx.hideNavigationBarLoading(Object object)

The navigation bar load animation is hidden on the current page

OBJECT parameter description:

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

wx.hideHomeButton(Object object)

Base library 2.8.3 is supported from now on, and low versions need to be compatible.

Hide the Back Home button. From WeChat version 7.0.7, when the bottom page of the user-opened small program is non-home, the default display "Back to home" button, developers can call hideHomeButton in the page onShow to hide.

OBJECT parameter description:

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)