zoukankan      html  css  js  c++  java
  • 微信小程序页面跳转方法总结

    微信小程序页面跳转目前有以下方法(不全面的欢迎补充):

    1. 利用小程序提供的 API 跳转:

    // 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。
    // 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,但是 redirectTo
    wx.navigateTo({
      url: 'page/home/home?user_id=111'
    })
    // 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。
    wx.navigateTo({ url: 'page/home/home?user_id=111'  // 页面 A })
    wx.navigateTo({
      url: 'page/detail/detail?product_id=222'  // 页面 B
    })
    // 跳转到页面 A
    wx.navigateBack({ delta: 2 })
    // 关闭当前页面,跳转到应用内的某个页面。
    wx.redirectTo({
      url: 'page/home/home?user_id=111'
    })
    // 跳转到tabBar页面(在app.json中注册过的tabBar页面),同时关闭其他非tabBar页面。
    wx.switchTab({
      url: 'page/index/index'
    })
    // 关闭所有页面,打开到应用内的某个页面。
    wx.reLanch({
      url: 'page/home/home?user_id=111'
    })

     2. wxml 页面组件跳转(可以通过设置open-type属性指明页面跳转方式):

      

    // navigator 组件默认的 open-type 为 navigate 
    <navigator url="/page/navigate/navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>
    // redirect 对应 API 中的 wx.redirect 方法
    <navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
    // switchTab 对应 API 中的 wx.switchTab 方法
    <navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
    // reLanch 对应 API 中的 wx.reLanch 方法
    <navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">关闭所有页面,打开到应用内的某个页面</navigator>
    // navigateBack 对应 API 中的 wx.navigateBack 方法
    <navigator url="/page/index/index" open-type="navigateBack" hover-class="other-navigator-hover">关闭当前页面,返回上一级页面或多级页面</navigator>
     

      

  • 相关阅读:
    【五校联考5day1】登山
    非旋Treap及其可持久化
    自然数幂求和——第二类Strling数
    [JZOJ6011] 【NOIP2019模拟1.25A组】天天爱跑步
    [JZOJ5232] 【NOIP2017模拟A组模拟8.5】带权排序
    FreeRTOS 任务通知模拟消息邮箱
    Python爬虫技术:爬虫时如何知道是否代理ip伪装成功?
    Python网络爬虫入门实战(爬取最近7天的天气以及最高/最低气温)
    Python numpy的基本操作你一般人都不会
    如何正确的使用Python解释器?你之前肯定用错了
  • 原文地址:https://www.cnblogs.com/yaoyuqian/p/7967472.html
Copyright © 2011-2022 走看看