在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ vue通過(guò)beforeEach從首頁(yè)跳轉(zhuǎn)到注冊(cè)頁(yè)面后,點(diǎn)擊返回會(huì)再次進(jìn)入首頁(yè)?

vue通過(guò)beforeEach從首頁(yè)跳轉(zhuǎn)到注冊(cè)頁(yè)面后,點(diǎn)擊返回會(huì)再次進(jìn)入首頁(yè)?

需求是進(jìn)入首頁(yè),通過(guò)uid判斷是否用戶為會(huì)員,如果不是會(huì)員,則跳轉(zhuǎn)到注冊(cè)頁(yè)面,但是有個(gè)問(wèn)題就是跳轉(zhuǎn)到注冊(cè)頁(yè)面后點(diǎn)擊返回按鈕,就會(huì)跳轉(zhuǎn)到上一頁(yè)面也就是首頁(yè)(然后由于不是會(huì)員就停留在了注冊(cè)頁(yè)),按邏輯頁(yè)也應(yīng)該是無(wú)限循環(huán)啊,實(shí)際上,我要點(diǎn)擊兩次返回按鈕才能退出注冊(cè)頁(yè)。困擾我多時(shí),往有人能幫解答,不勝感激!

進(jìn)入首頁(yè)memberCenter后,輸出
to memberCenter
to register

第一次點(diǎn)擊返回按鈕,輸出,并停留在注冊(cè)頁(yè)面
to memberCenter

第二次點(diǎn)擊返回按鈕,退出注冊(cè)頁(yè)面(即退出微信公眾號(hào),但跟微信無(wú)關(guān),其他瀏覽器也有這個(gè)問(wèn)題)

代碼

router.beforeEach(async (to, from, next) => {
  console.log('to', to.name);
  Indicator.open('努力加載中...');

  // 注冊(cè)時(shí)進(jìn)入會(huì)員中心會(huì)請(qǐng)求會(huì)員中心接口,注冊(cè)后需要更新會(huì)員中心接口
  if (to.path === '/memberCenter') {
    // 會(huì)員中心數(shù)據(jù)為空
    if (!store.state.memberCenterData) {
      await store.dispatch('getMemberCenterAction');
    }

    Vue.prototype.$nextTick(() => {
      Indicator.close();
    });

    if (store.state.memberCenterData.uid) {
      next({
        path: '/register',
      });
      return;
    }
  }
  next();
});

補(bǔ)充:
另外在首頁(yè)(也就是會(huì)員中心)通過(guò)beforeRouteEnter里的next({name: 'register'})跳轉(zhuǎn)到注冊(cè)頁(yè),在注冊(cè)點(diǎn)擊返回也會(huì)返回到上一頁(yè),好像全局的beforeEach和組件的beforeRouteEnter里的next()作用都變成了router.push(),而我想要是類(lèi)似router.replace()的效果

回答
編輯回答
尤禮

沒(méi)遇到過(guò)需要點(diǎn)擊兩次才能到首頁(yè)的情況。
不過(guò)要實(shí)現(xiàn)需要還是容易的,只要判斷是注冊(cè)頁(yè)到主頁(yè)的跳轉(zhuǎn)就直接next(),這滿足你的需求。

  if (to.path === '/memberCenter') {
    // 會(huì)員中心數(shù)據(jù)為空
    if(from.path==='/register'){
      next();
      return;
     }else{
     ...
     }
  }

你這鉤子是不會(huì)無(wú)限跳轉(zhuǎn)的,因?yàn)槟銢](méi)有寫(xiě)to.name=='/register'的鉤子

2018年3月30日 22:34