2016-09-07 122 views
0

我使用流星與FlowRouter,我在尋找這樣一個條件: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

我會說,你只需要改變你的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

相關問題