我使用内置的LoginButtons选项和Meteor,我想在用户登录后重定向。使用内置的web片段意味着我不能使用Meteor的回调.loginwithPassword和我看不到Iron-Router内部的任何钩子来做重定向。使用Meteor和铁路路由器登录后重定向
有什么建议吗?
我使用内置的LoginButtons选项和Meteor,我想在用户登录后重定向。使用内置的web片段意味着我不能使用Meteor的回调.loginwithPassword和我看不到Iron-Router内部的任何钩子来做重定向。使用Meteor和铁路路由器登录后重定向
有什么建议吗?
流星往往呈现如此迅速,用户已经定义之前的页面被加载。你需要使用Meteor.loggingIn()
来占你在登录过程是情况此代码的工作对我来说:
this.route('myAccount', {
path: '/',
onBeforeAction: function() {
if (! Meteor.user()) {
if (!Meteor.loggingIn()) Router.go('login');
}
}
}
'if(!Meteor.loggingIn())Router.go('login');' –
应该很简单,你只添加类似配置现有的途径之一:
Tracker.autorun(function() {
var currentRoute = Router.current();
if (currentRoute === null) {
return;
}
if (currentRoute.route.getName() === 'login' && Meteor.user() !== null)
Router.go('WelcomeNewUser');
}
如果用户未登录,您也可以使用与其他模板相同的路线。
就像这样:
this.route('myAccount', {
before: function() {
if (!Meteor.user()) {
this.render('login');
this.stop();
}
}
}
没有魔法,只是进去看了docs;)
这个例子可能是有用的
// main route render a template
Router.route('/', function() {
this.render('main');
});
// render login template
Router.route('/login', function() {
this.render('login');
});
// we want to be sure that the user is logging in
// for all routes but login
Router.onBeforeAction(function() {
if (!Meteor.user() && !Meteor.loggingIn()) {
this.redirect('/login');
} else {
// required by Iron to process the route handler
this.next();
}
}, {
except: ['login']
});
// add here other routes
// catchall route
Router.route('/(.*)', function() {
this.redirect('/catchallpage');
});
你尝试这个https://github.com/EventedMind/iron-router#using-hooks Router.before(mustBeSignedIn,{except:['login','signup','forgotPassword']}); – pahan
我看不到任何使用此示例的代码段,看看如何使用它 – user2243825