Hide the forward button in the navigation bar

The onShareAppMessage function is defined in Page to set the forwarding information of the Page. If you want to disable the forwarding of the current Page, delete this function.

Setting page Forwarding

onShareAppMessage(Object object)

Monitor the behavior of users clicking the forward button in the page (button component open-type=”share”) or the “forward” button in the menu in the upper right corner, and customize the forwarding content.

Note: Only if this event handler is defined will the forward button appear in the upper-right menu

This event handler needs to return an Object, which is used to customize the forward content.

Page({
  onShareAppMessage: function (res) {
    return {
      title: 'Custom Forwarding title'.path: '/page/user? id=123'.success: function(res) {
        // Forwarding succeeded
      },
      fail: function(res) {
        // Forwarding failed}}}})Copy the code
1. Identify whether to forward to individuals or groups
  1. It can only be obtained if it is forwarded to a group chat and openedshareTicketsReturn value, single chat has noshareTickets
  2. shareTicketValid only during the current applets life cycle
wx.showShareMenu({
  withShareTicket: true
})
Copy the code
2. Multiple forward buttons

When there are multiple forwarding buttons in a page, the forwarding page of each button is different. You do a separate setting in the onShareAppMessage function. The onShareAppMessage function has the options parameter. The options parameter contains the source from which the function was triggered. The from parameter in options indicates the source of the forwarding event.

Button: forwarding button within the page; Menu: indicates the forward menu in the upper right corner. If it is a button, the target parameter in the button can be used to determine which button is triggered, and the ID or class of the button can be obtained. This allows you to set up different forwarding pages for different buttons

Page({
  onShareAppMessage: function (res) {
    / / button to trigger
    if (res.from === 'button') { 
      let target_id = res.target.id;      // Button with id btn1 is triggered
      if (target_id === "btn1") {        
      return {
          title: 'Forward one'.path: '/page/index'.success: function(res) {
            // Forwarding succeeded
          },
          fail: function(res) {
            // Forwarding failed}}// Button with id btn2 is triggered
      }else if((target_id === "btn2")) {return {
          title: 'Forward two'.path: '/page/user'.success: function(res) {
            // Forwarding succeeded
          },
          fail: function(res) {
            // Forwarding failed}}}/ / the menu trigger
    }else if (res.from === 'menu') {        return {
          title: 'menu forward'.path: '/page/user'.success: function(res) {
            // Forwarding succeeded
          },
          fail: function(res) {
            // Forwarding failed}}}}})Copy the code

Note: The forwarding of menu should be set separately

3. Forwarding band parameters

If you need parameters when another user clicks forward to enter the applet, you can put the required values in the onShareAppMessage function for forwarding.

Page({
  onShareAppMessage: function (res) {
    let sendinfo = {
      num: 1.nickName: "jack",}let str = JSON.stringify(sendinfo);    
    return {
      title: nickName + 'I shared a little program with you.'.path: '/page/user? sendinfo=' + sendinfo,
      success: function(res) {
        // Forwarding succeeded
      },
      fail: function(res) {
        // Forwarding failed}}}})Copy the code

Now click the forward card and you can get the value in the forward path address page.

Page({
  data:{
  }
  onLoad: function (options) {
    letsendinfo = options.sendinfo ; }})Copy the code