微信小程序获取当前页面路由,并重新加载小程序!

57 阅读1分钟
//获取当前页面路由已经参数
     getCurrentPageFullPath (){
      //微信内置方法 直接调
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1];
      const { route, options } = currentPage;

      // 拼接参数(如:pages/detail/detail?id=123&name=test)
      const params = Object.keys(options).map(key => `${key}=${options[key]}`).join('&');
      return params ? `${route}?${params}` : route;
    },
    //在按钮事件中写入该方法, 改方法不会清空storage
    wx.restartMiniProgram({
        path: `/${this.getCurrentPageFullPath()}`
      })