我需要一些帮助。我为我的应用程序配置了注册页面,它运行良好,但现在我希望一个用户在验证后被发送回他们点击注册前的确切网址。我看过流星文档,并使用了session.set和session.get;它们可以工作,但只用于洞察应用程序。一旦用户单击验证链接,我就无法使用session.get返回存储在session.set中的确切网页。相关代码如下-任何洞察力都将不胜感激--谢谢!
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');
}
});
}
});
});发布于 2016-11-29 01:20:01
在这种情况下,您不能使用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');
}
});
}
});
});https://stackoverflow.com/questions/40855495
复制相似问题