2016-11-28 48 views
2

我需要一些幫助。我爲我的應用程序配置了註冊頁面,並且它工作正常,但現在我希望用戶在驗證之後能夠返回到它們在點擊註冊前的確切網址。我查看了流星文檔並使用了session.set和session.get;他們的工作,但只爲了解應用程序的事情。似乎用戶點擊驗證鏈接後,我無法使用session.get返回存儲在session.set中的確切網頁。相關的代碼如下 - 任何見解將不勝感激 - 先謝謝了!流星Session.set,Session.get

Template.applyPageOne.events({ 
    'click .jsCandidateSignupRequest': function (event) { 
     event.preventDefault(); 
     var applyUrlSet = window.location.href; 
     Session.set('applyUrlSession', applyUrlSet); 
     Router.go('signupCandidate'); 
    } 
}); 

Router.map(function() { 
    this.route('verifyEmail', { 
     controller: 'AccountController', 
     path: '/verify-email/:token', 
     action: 'verifyEmail' 
    }); 
    AccountController = RouteController.extend({ 
     verifyEmail: function() { 
      Accounts.verifyEmail(this.params.token, function() { 
       if(Roles.userIsInRole(Meteor.user(), ['candidate'])) { 
        var applyUrlGet = Session.get('applyUrlSession'); 
        window.open(applyUrlGet,'_self', false); 
       }else { 
        Router.go('dashboard'); 
       } 
      }); 
     } 
    }); 
}); 

回答

1

在這種情況下,您不能使用Session,因爲Session的值不會在瀏覽器的選項卡之間共享。

我建議使用localStorage存儲鏈接,像這樣:

Template.applyPageOne.events({ 
    'click .jsCandidateSignupRequest': function(event) { 
    event.preventDefault(); 
    var applyUrlSet = window.location.href; 
    localStorage.setItem('applyUrlSession', applyUrlSet); 
    Router.go('signupCandidate'); 
    } 
}); 

Router.map(function() { 
    this.route('verifyEmail', { 
    controller: 'AccountController', 
    path: '/verify-email/:token', 
    action: 'verifyEmail' 
    }); 
    AccountController = RouteController.extend({ 
    verifyEmail: function() { 
     Accounts.verifyEmail(this.params.token, function() { 
     if (Roles.userIsInRole(Meteor.user(), ['candidate'])) { 
      var applyUrlGet = localStorage.getItem('applyUrlSession'); 
      localStorage.removeItem('applyUrlSession'); 
      window.open(applyUrlGet, '_self', false); 
     } else { 
      Router.go('dashboard'); 
     } 
     }); 
    } 
    }); 
}); 
+0

工作就像一個魅力。我很高興你分享你的見解。我還閱讀了您分享的localStorage文檔 - 再次感謝! – Mike

+0

也值得知道Meteor使用localStorage來存儲用戶登錄標記:) – Khang