In the development of wechat applets, we often encounter the need to forward the current page to friends. And most of the time, forwarded pages have parameters. There are a lot of holes in here.

  <button open-type="share" type="primary">Share with friends</button>
Copy the code

First, we’ll write a button button. An important point is the open-type property of the button, which must be called share. In fact, what happens is that the onShareAppMessage lifecycle function is triggered by a button.

  onShareAppMessage: function (res) {
    var that = this;
    console.log(JSON.stringify(that.data.array))
    return {
      title:that.data.array.name,
      path:'pages/detail/detail? array=' + JSON.stringify(that.data.array),
      imageUrl:that.data.array.pic
    }
  }
})
Copy the code

The key is to return an object, the core of the three properties, title, path, imageUrl

Title is the title, path is the path to the page after clicking, and imageUrl is the image displayed. This path supports parameter passing because most requirements require parameters.

I this small program is a recipe small program, users see a satisfactory dish, want to share with friends, friends click the link to go in, must be to jump to the dish I see, so this demand is bound to be achieved through the URL transfer parameter.

By the way, I recently developed a small menu program, currently more than 10,000 dishes on display, welcome to experience. Wechat direct search small program: super recipe A

The above can achieve the expected function, and can accurately jump forward the page.