我正在使用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'});
}
});
答案 0 :(得分:0)
if(Meteor.userId() && FlowRouter.getRouteName() === 'route_name'){
FlowRouter.go('/route_name');
}
在流路由器文档中,如果需要重构上述语句,有一些是获取当前路由。 https://github.com/kadirahq/flow-router/blob/master/README.md
答案 1 :(得分:0)
我说你只需更改一下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