The latest project is doing wechat mini program. Then, a very strange order is raised. When the user jumps several times in the interface, the route jump will be invalid after a certain number of jumps. In our project, MPVue was used, vue-Router was used for routing jump, and no error was reported. After reviewing relevant data, we found that the history stack of applets is limited to 5 layers. Wx. navigateTo is invalid if you continue to call it. This.$router.push is the same method as wx.redirectTo.

wx.navigateTo({
    url: `http://yourUrl`,
    fail: (err) => {
      console.error(err)
      wx.redirectTo({
        url: `http://yourUrl`
      })
    }
})
Copy the code

The problem with this solution is that a -> B; b –> c; c –> d; d –> e; e –> f; f –> g; Now, if YOU go back to page G, you’re not going to get page F, you’re going to get page E, because page E is level 4.

As an alternative, the Wx. reLaunch API clears the previous route history and sets the destination route to level 1 route history.

wx.navigateTo({
    url: `http://yourUrl`,
    fail: (err) => {
      console.error(err)
      wx.reLaunch({
        url: `http://yourUrl`
      })
    }
})
Copy the code

The idea behind this solution is to empty the Histroy stack every time it fills up and then restart the stack. The drawback is that each time you restart, the backward operation fails because there is only one record in the stack.