首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >流星Session.set,Session.get

流星Session.set,Session.get
EN

Stack Overflow用户
提问于 2016-11-28 23:48:57
回答 1查看 119关注 0票数 2

我需要一些帮助。我为我的应用程序配置了注册页面,它运行良好,但现在我希望一个用户在验证后被发送回他们点击注册前的确切网址。我看过流星文档,并使用了session.set和session.get;它们可以工作,但只用于洞察应用程序。一旦用户单击验证链接,我就无法使用session.get返回存储在session.set中的确切网页。相关代码如下-任何洞察力都将不胜感激--谢谢!

代码语言:javascript
复制
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');
                }
            });
        }
    });
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-29 01:20:01

在这种情况下,您不能使用Session,因为会话的值在浏览器的选项卡之间不共享。

我建议使用localStorage来存储链接,如下所示:

代码语言:javascript
复制
 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');
        }
      });
    }
  });
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40855495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档