[英]FlowRouter redirect if user is logged in and if path is
我正在将Meteor与FlowRouter配合使用,并且正在寻找类似这样的情况:
我目前的路线:
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');
}
在流路由器文档中,如果您需要重组上面的语句,则有一些方法可以获取当前路由。 https://github.com/kadirahq/flow-router/blob/master/README.md
我想说的是,您只需要稍微更改FlowRouter.route('/'...)配置即可:
FlowRouter.route('/', {
triggersEnter: [function(context, redirect) {
if (Meteor.userId()) {
redirect('/clients');
}
}],
name: 'home',
action(){
BlazeLayout.render('HomeLayout');
}
});
因此,任何访问“ /”的登录用户都将被重定向到“客户端”-在我测试时可以正常工作。 这是流路由器文档中的一些背景信息: https : //github.com/kadirahq/flow-router/blob/master/README.md#redirecting-with-triggers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.