gogoWebsite

How to exit a small program inside a WeChat small program

Updated to 6 months ago

The company asked to use a small program to reconstruct the existing WeChat public number, so I did not touch the small program. Okay, straight to the point.

How to exit the applet inside the applet

This function is basically used, and there is no direct api found inside the documentation such as microsoft:

 ('closeWindow');

So I googled all sorts of things, and well, the results tell me that the applet has come out with this api, but it's not publicly available = =||| That means thatpresent .There is no api for this (lift the table!). There is a way to do this.Make one yourself using the existing api


Yes, it's with these beauties.

First we have two pages, index and a.

Set a global variable flag:

 globalData: {
    flag:false
 }

 <button  bindtap='toa'>to a</button>


 toa(){// Jump to page a
    ({
      url: '... /a/a',
    })
  },
 onLoad: function () {
    if () {// if flag is true, exit
      ({
        delta:1
      })
    } else {
      ('Here is index')
    }
  },


:

<!--pages/a/-->
<text>pages/a/</text>
<button bindtap='close'>close</button>


 close(){
    =true;
    ({
      url: '../index/index',
    })    
  },
Click the button to a to jump to page a, then click close to exit the applet.

Here, the close function is going to set the global variable to true, and then use to close all the pages, and when jumping to index, utilize to return to the previous page, because theThere's nothing in the page stack, and it quits the applet.


Take a screenshot: