[英]FlowRouter redirect if user is logged in and if path is
I'm using Meteor with FlowRouter and i'm looking for a condition like this: 我正在将Meteor与FlowRouter配合使用,并且正在寻找类似这样的情况:
My current Routes: 我目前的路线:
Accounts.onLogin(function(){
FlowRouter.go('clients');
});
Accounts.onLogout(function(){
FlowRouter.go('home')
});
FlowRouter.triggers.enter([function(context, redirect){
if(!Meteor.userId()){
FlowRouter.go('home')
}
}]);
FlowRouter.route('/', {
name: 'home',
action(){
BlazeLayout.render('HomeLayout');
}
});
FlowRouter.route('/clients',{
name: 'clients',
action(){
BlazeLayout.render('MainLayout', {main: 'Clients'});
}
});
if(Meteor.userId() && FlowRouter.getRouteName() === 'route_name'){
FlowRouter.go('/route_name');
}
In flow router docs there are a few was to get the current route if you need to restructure the statement above. 在流路由器文档中,如果您需要重组上面的语句,则有一些方法可以获取当前路由。 https://github.com/kadirahq/flow-router/blob/master/README.md https://github.com/kadirahq/flow-router/blob/master/README.md
I'd say that you just have to change your FlowRouter.route('/'...) configuration a bit: 我想说的是,您只需要稍微更改FlowRouter.route('/'...)配置即可:
FlowRouter.route('/', {
triggersEnter: [function(context, redirect) {
if (Meteor.userId()) {
redirect('/clients');
}
}],
name: 'home',
action(){
BlazeLayout.render('HomeLayout');
}
});
So any logged in user that accesses '/' will be redirected to 'clients' - worked fine when I tested it. 因此,任何访问“ /”的登录用户都将被重定向到“客户端”-在我测试时可以正常工作。 Here's some background info in the flow router docs: https://github.com/kadirahq/flow-router/blob/master/README.md#redirecting-with-triggers 这是流路由器文档中的一些背景信息: https : //github.com/kadirahq/flow-router/blob/master/README.md#redirecting-with-triggers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.