Vue global routing beforeEach execution judgment is an error

prompts you to report an error when verifying whether it is a Wechat browser:

clipboard.png

:

clipboard.png

Global routing judgment Code:

router.beforeEach((to,from,next)=>{

  // title
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  // 
  if((_need && isWeiXin()) ||!_need){
    next();
  }else{
    next({ path: "/error", replace: true, query: { noGoBack: true }})
  }
})

do you know what the reason is and how to solve it?


is the routing of / error running in an endless loop, and it is not judged to release it directly by next when / error is removed


positive solution upstairs, and then went to adjust

router.beforeEach((to,from,next)=>{

  // title
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  //next()
  if((_need && isWeiXin()) ||!_need){
    next()
  }else{
    ///error  beforeEach,
    if(to.path==='/error'){ //
      next()
    }else{
      next({ path: '/error',replace:true, query: { noGoBack: true }})
    }
  }

})
Menu