search
HomeWeChat AppletMini Program DevelopmentHow to return to the homepage of WeChat Mini Program

When developing small programs, I found that after a page is shared, it is difficult for users to return to the home page through the shared page. (The official operation of WeChat is to click the three dots in the upper right corner, which will be displayed below the phone to return to the homepage). Many private solutions are to add a floating Home mark to the page yourself.

Today I will share another method. Please look at the .gif below;

Have you noticed that there is a return button in the upper left corner? The principle is simple. On the page you want to share, configure your homepage when sharing the configuration, and bring the corresponding parameters, which can be obtained in the onLoad method of the homepage. The code is as follows:


<!--index.wxml-->
<view class="container">
<text>我是首页</text>
 <button bindtap=&#39;goLogs&#39;>go logsPage</button>
</view>

const app = getApp()

Page({
 data: {
  motto: &#39;Hello World&#39;,
  userInfo: {},
  hasUserInfo: false,
  canIUse: wx.canIUse(&#39;button.open-type.getUserInfo&#39;)
 },
 //事件处理函数
 goLogs: function() {
  wx.navigateTo({
   url: &#39;/pages/logs/logs&#39;
  })
 },
 onLoad: function (options) {
  console.log(options)
  if (options.share_query){
   wx.showLoading({
    title: &#39;我是从分享页面进入的&#39;,
   })

   setTimeout(function () {
    wx.hideLoading()
    wx.navigateTo({
     url: &#39;/pages/logs/logs&#39;,
    })
   }, 2000)

  
  }

  }
 
})
<!--logs.wxml-->
<view class="container log-list">
 <block wx:for="{{logs}}" wx:for-item="log">
  <text class="log-item">{{index + 1}}. {{log}}</text>
 </block>
</view>
const app = getApp()

Page({
 data: {
  motto: &#39;Hello World&#39;,
  userInfo: {},
  hasUserInfo: false,
  canIUse: wx.canIUse(&#39;button.open-type.getUserInfo&#39;)
 },
 //事件处理函数
 goLogs: function() {
  wx.navigateTo({
   url: &#39;/pages/logs/logs&#39;
  })
 },
 onLoad: function (options) {
  console.log(options)
  //判断是否分享进入
  if (options.share_query){
   wx.showLoading({
    title: &#39;我是从分享页面进入的&#39;,
   })

   setTimeout(function () {
    wx.hideLoading()
    wx.navigateTo({
     url: &#39;/pages/logs/logs&#39;,
    })
   }, 2000)  
  }
  } 
})

The above is the detailed content of How to return to the homepage of WeChat Mini Program. 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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft