鍍金池/ 問答/HTML5  HTML/ vue 全局路由beforeEach執(zhí)行判斷是報錯

vue 全局路由beforeEach執(zhí)行判斷是報錯

在執(zhí)行校驗是否微信瀏覽器時,提示報錯:

clipboard.png

路由截圖:

clipboard.png

全局路由判斷代碼:

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

  // 設(shè)置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 }})
  }
})

有知道是什么原因,怎么解決的么?

回答
編輯回答
只愛你

是不是 /error 的路由死循環(huán)了,沒有判斷去/error的時候直接next 釋放掉呢

2017年9月12日 05:24
編輯回答
晚風(fēng)眠

樓上正解,然后去進(jìn)行了調(diào)整

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

  // 設(shè)置title
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  //next()
  if((_need && isWeiXin()) ||!_need){
    next()
  }else{
    ///error 會在進(jìn)入前 又要進(jìn)入beforeEach中,這樣就會一直循環(huán)下去
    if(to.path==='/error'){ //跳出循環(huán)的關(guān)鍵
      next()
    }else{
      next({ path: '/error',replace:true, query: { noGoBack: true }})
    }
  }

})
2017年1月14日 06:38