search
HomeWeChat AppletMini Program DevelopmentShare solutions to the problem of blank page redirection in WeChat mini programs

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

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools