h5跳转小程序页面url_微信小程序页面跳转方法

f4b41bbe8b58e181e7a5906106876b50.png
我所知道的,微信小程序页面跳转有以下方法,下面分情况说明下

一、利用小程序提供的 API 跳转:

1、简单page页面之间跳转

// 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。
(注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,但是 redirectTo不会)

wx.navigateTo({
  url: 'page/home/home?user_id=111'
})

// 关闭当前页面,跳转到应用内的某个页面。

wx.redirectTo({
  url: 'page/home/home?user_id=111'
})

2、page页面之间跳转后触发点击事件返回跳转前的页面

// 关闭当前页面,返回上一页面或多级页面。可通过 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
})

3、从page跳转到topbar页面

// 跳转到tabBar页面(在app.json中注册过的tabBar页面),同时关闭其他非tabBar页面。

wx.switchTab({
  url: 'page/index/index'
})

4、直接到应用内的某个页面

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

wx.reLanch({
  url: 'page/home/home?user_id=111'
})

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

1、跳转到新页面

// navigator 组件默认的 open-type 为 navigate

<navigator url="/page/navigate/navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>

2、在当前页打开

// redirect 对应 API 中的 wx.redirect 方法

<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>

3、切换 Tab

// switchTab 对应 API 中的 wx.switchTab 方法

<navigatorurl="/page/index/index"open-type="switchTab"hover-class="other-navigator-hover">切换 Tab</navigator>

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

// reLanch 对应 API 中的 wx.reLanch 方法

<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">关闭所有页面,打开到应用内的某个页面</navigator>

5、关闭当前页面,返回上一级页面或多级页面

// navigateBack 对应 API 中的 wx.navigateBack 方法

<navigatorurl="/page/index/index"open-type="navigateBack"hover-class="other-navigator-hover">关闭当前页面,返回上一级页面或多级页面</navigator>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值