Uniapp API Content Redirection Guide

In uniapp, you can achieve content redirection by using either the uni.navigateTo or uni.redirectTo method. Both of these methods will navigate to the specified page in the application and can pass parameters to the target page.

  1. Achieve content redirection using the uni.navigateTo method.
uni.navigateTo({
  url: 'pages/targetPage',
  success: function(res) {
    console.log(res)
  },
  fail: function(err) {
    console.log(err)
  }
})
  1. Implement content redirection using the uni.redirectTo method.
uni.redirectTo({
  url: 'pages/targetPage',
  success: function(res) {
    console.log(res)
  },
  fail: function(err) {
    console.log(err)
  }
})

On the target page, you can retrieve the passed parameters using either uni.getStorageSync or uni.getStorage method.

// 目标页面中获取参数
let params = uni.getStorageSync('key')
console.log(params)

或者

uni.getStorage({
  key: 'key',
  success: function(res) {
    console.log(res.data)
  },
  fail: function(err) {
    console.log(err)
  }
})

By following the above method, you can achieve the implementation of content redirection and passing parameters to the target page in UniApp.

bannerAds