Applet basis (five)

Routing Jump

The official document: https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.switchTab.html

1.wx.switchTab(Object.object)

TabBar can only jump to the page, and close all other non-tabBar page (note: tabBar here refers to the navigation bar at the bottom of the page specified)

Parameter Object object

img

Sample Code

In wxml page

<button bindtap='click'>按钮</button>

In js page

click:function(){
    wx.switchTab({
      url: "/pages/test/test"   #注意路径最前面写个/,而且路径只能写tabBar里面的,不能携带参数
    })
  }

2.wx.reLaunch (Object.object) can be parameterized

Close all pages within the application to open a page

Parameter Object object

img

Sample code:

wxml page

<button bindtap='click'>按钮</button>

js page (Note: You can pass parameters by stitching?)

click:function(){
    var name="jj";
    wx.reLaunch({
      url: '/pages/test2/test2?name='+name     #跳转到test2页面
    })
  }

3.wx.redirectTo(Object object)

Close the current page, jump to a page, but not allowed to jump to the page tabBar

Parameter Object object

img

Sample Code

js page

click:function(){
    var name="jj";
    wx.redirectTo({
      url: '/pages/test3/test3?name='+name     #跳转到test3页面
    })
  }

4.wx.navigateTo(Object object)

Retain the current page, jump to a page within the application. But you can not jump tabBar page, use wx.navigateBack can return to the page, return up to ten layers.

Parameter Object object

img

Sample Code

test1.js page

click:function(){
    wx.navigateTo({
      url: '/pages/test3/test3?id=1'     #跳转到test3页面
    })
  }

test3.js page

Page({
   onLoad(option){
     console.log("我是test3")
} 
})

5.wx.navigateBack(Object object)

Close the current page to the previous page or multi-page level, you can get the current page by getCurrentPages (), the decision needs to return several layers.

Parameter Object object

img

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
})

Guess you like

Origin www.cnblogs.com/chmily/p/12055178.html