Share solutions to the problem of blank page redirection in WeChat mini programs

黄舟
Release: 2018-05-24 09:26:10
Original
6854 people have browsed it

This article mainly introduces the relevant information on the solution to the blank page redirection of the WeChat applet. Friends in need can refer to the following

The solution to the blank page redirection of the WeChat applet

At the beginning, the entry file of the mini program was pointed directly to the homepage of the tabbar. At this time, a problem occurred: the QR code scan did not close the homepage for the first time, and did not go through the onLoad process when entering for the second time. Parse scene parameters;

Official explanation: The life cycle triggered by tabbar jump mode is onShow, without onLoad, as shown below:

At this time, When discussing the redirection problem with my friends, I thought that it could be done using a similar method, so I immediately implemented it:

Add pages/index/index (entry file), pages/home/home (tabbar) to app.json Page homepage), pages/detail/detail (details page); pages/exclusive/exclusive

OnLoad processing in index.js:

/**
  * 生命周期函数--监听页面加载
  */
 onLoad: function (options) {
  // 入口文件 决定进入哪个页面
  console.log('入口文件,参数scene,值detail%2C1127')
  var scene = options.scene; //扫码进入有此参数
  var scene = decodeURIComponent(options.scene);
  if (scene) {
   //'scene=detail%2C1127' 分隔符, 测试时为 , 号;真机时为%2C 原因是url编码,但是使用decodeURI()解析不出来,所以走了兼容
   
   let info_arr = [];
   info_arr = scene.split(',');
   //console.log(info_arr)
   let _type = info_arr[0];
   let id = info_arr[1];
   if (_type == 'detail') {
    wx.redirectTo({ url: `../detail/detail?id=${id}`, })
   } else if (_type == 'exclusive') {
    wx.redirectTo({ url: `../exclusive/exclusive?id=${id}`, })
   }
  }else{
   wx.switchTab({
    url: '../home/home',
   })
  }
 },
Copy after login

At this time, perfect Solve the problem that scanning the QR code-->home-->detail; and scanning the QR code-->home again cannot reach-->detail;

Scan the QR code-->index(redirectTo )-->detail;Scan the code again-->index (redirectTo)-->detail problem; past the home page

Since the home page has a large number of requests, it is not suitable to use redirectTo; so this The method is a compromise choice

The above is the detailed content of Share solutions to the problem of blank page redirection in WeChat mini programs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template