Applet routing Jump

1 small program routing Jump

1.1wx.switchTab(Object object)

tabBar here is the navigation bar under the specified page,

TabBar jump to the page, and close all other non-tabBar page

parameter

Object object

Attributes Types of Defaults Mandatory Explanation
url string   Yes Path requires tabBar page jump (in need of app.json  tabBar  field defines the page), not the path parameters.
success function   no Interface call success callback function
fail function   no Interface calls the failure callback function
complete function   no Interface calls the end of the callback function (call succeeds, the failure will be executed)

Sample Code

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

1.2wx.reLaunch(Object object)

Infrastructure Library 1.1.0 support, low version to be made compatible with the process .

Close all pages within the application to open a page

parameter

Object object

Attributes Types of Defaults Mandatory Explanation
url string   Yes Need to jump in applications Page path, the path can be parameterized. ? Parameters used between the partition and the path, and the key parameters = parameter value connected with the different parameters & separated; as '? Path key = value & key2 = value2'
success function   no Interface call success callback function
fail function   no Interface calls the failure callback function
complete function   no Interface calls the end of the callback function (call succeeds, the failure will be executed)

Sample Code

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

// test Page({ onLoad (option) { console.log(option.query) } })

1.3wx.redirectTo(Object object)

Close the current page, jump to a page within the application. But does not allow tabbar jump to the page.

parameter

Object object

Attributes Types of Defaults Mandatory Explanation
url string   Yes A jump path in applications requiring non tabBar pages, the path can be parameterized. Parameters using the path between  ? the partition, the key parameters of the parameter value  = connected with the different parameters of  & the partition; as '? Path key = value & key2 = value2'
success function   no Interface call success callback function
fail function   no Interface calls the failure callback function
complete function   no Interface calls the end of the callback function (call succeeds, the failure will be executed)

Sample Code

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

1.4wx.navigateTo(Object object)

Retain the current page, jump to a page within the application. But not jump tabbar page. Use  wx.navigateBack  can return to the original page. Applet page stack up to ten layers.

parameter

Object object

Attributes Types of Defaults Mandatory Explanation
url string   Yes A jump path in applications requiring non tabBar pages, the path can be parameterized. Parameters using the path between  ? the partition, the key parameters of the parameter value  = connected with the different parameters of  & the partition; as '? Path key = value & key2 = value2'
success function   no Interface call success callback function
fail function   no Interface calls the failure callback function
complete function   no Interface calls the end of the callback function (call succeeds, the failure will be executed)

Sample Code

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

// test.js
Page({
  onLoad(option) {
    console.log(option.query)
  }
})

1.5wx.redirectTo the difference between wx.navigateTo

1. Using wx.navigateTo jump to the next page of time (this time will perform onHide method), the next page will head back button

2. If you do not have a back button, you can jump page with wx.redirectTo (this time to close this page, performs onUnload life cycle, so there would be no return to the next page buttons, because a page has been turned off , pages can be returned)

1.6wx.navigateBack(Object object)

Close the current page to the previous page or multi-level page. By  getCurrentPages ()  Gets the current page stack, the decision needs to return several layers.

parameter

Object object

Attributes Types of Defaults Mandatory Explanation
delta number   Yes The number of pages returned if the delta is greater than the existing number of pages, then return to the home.
success function   no Interface call success callback function
fail function   no Interface calls the failure callback function
complete function   no Interface calls the end of the callback function (call succeeds, the failure will be executed)

Sample Code

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

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

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

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

1.1wx.switchTab(Object object)

tabBar here is the navigation bar under the specified page,

TabBar jump to the page, and close all other non-tabBar page

parameter

Object object

Attributes Types of Defaults Mandatory Explanation
url string   Yes 需要跳转的 tabBar 页面的路径(需在 app.json 的 tabBar 字段定义的页面),路径后不能带参数。
success function   接口调用成功的回调函数
fail function   接口调用失败的回调函数
complete function   接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

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

1.2wx.reLaunch(Object object)

基础库 1.1.0 开始支持,低版本需做兼容处理

关闭所有页面,打开到应用内的某个页面

参数

Object object

属性 类型 默认值 必填 说明
url string   需要跳转的应用内页面路径,路径后可以带参数。参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔;如 'path?key=value&key2=value2'
success function   接口调用成功的回调函数
fail function   接口调用失败的回调函数
complete function   接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

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

// test Page({ onLoad (option) { console.log(option.query) } })

1.3wx.redirectTo(Object object)

关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。

参数

Object object

属性 类型 默认值 必填 说明
url string   需要跳转的应用内非 tabBar 的页面的路径, 路径后可以带参数。参数与路径之间使用 ? 分隔,参数键与参数值用 = 相连,不同参数用 & 分隔;如 'path?key=value&key2=value2'
success function   接口调用成功的回调函数
fail function   接口调用失败的回调函数
complete function   接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

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

1.4wx.navigateTo(Object object)

保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 wx.navigateBack 可以返回到原页面。小程序中页面栈最多十层。

参数

Object object

属性 类型 默认值 必填 说明
url string   需要跳转的应用内非 tabBar 的页面的路径, 路径后可以带参数。参数与路径之间使用 ? 分隔,参数键与参数值用 = 相连,不同参数用 & 分隔;如 'path?key=value&key2=value2'
success function   接口调用成功的回调函数
fail function   接口调用失败的回调函数
complete function   接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

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

// test.js
Page({
  onLoad(option) {
    console.log(option.query)
  }
})

1.5wx.redirectTo与wx.navigateTo的区别

1.利用wx.navigateTo跳转到下一个页面的时候(这时候会执行onHide方法),下一个页面头部会有返回按钮

2.如果不想有返回按钮,可以用wx.redirectTo进行页面跳转(这时候关闭此页面,会执行onUnload生命周期,这样下一个页面就不会有返回按钮了,因为上一个页面已经被关闭了,没有页面可以返回)

1.6wx.navigateBack(Object object)

关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。

参数

Object object

属性 类型 默认值 必填 说明
delta number   返回的页面数,如果 delta 大于现有页面数,则返回到首页。
success function   接口调用成功的回调函数
fail function   接口调用失败的回调函数
complete function   接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

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

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

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

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

Guess you like

Origin www.cnblogs.com/cherish937426/p/11853561.html