wx.onAppRoute已经失效

最近试图使用wx.onAppRoute来设置一些全局的东西,比如给每个页面都设置onShareAppMessage方法,让每个页面都可以分享:

//app.js
onLaunch(){
    wx.onAppRoute(()=>{
        const pages = getCurrentPages();
        const currPage = pages[pages.length - 1];

        if (currPage.onShareAppMessage !== undefined) return;

        currPage.onShareAppMessage = ()=>{
            return { title: 'Hi' }
        }
    })
}

这样的做法已经失效了,点击右上角的三个点,分享按钮还是灰色的。
难道是我使用的方法不对吗?如果有错误请告诉我~

还可以使用behaviors

幸运的是,现在Page也支持behaviors了,虽然还是要每个页面都引用定义的behaviors,但是总比每个页面都写上一段相同的代码好一点。

End

标签: wx.onAppRoute