簡體   English   中英

Account.onLogin()上的FlowRouter在Meteor中無法正確重定向

[英]FlowRouter on Account.onLogin() doesn't redirect properly in Meteor

我所有的路由都工作正常,並且在“ D:\\ test \\ imports \\ startup \\ client \\ routes.js ”中聲明了我的路由。

  1. 我添加了一個軟件包“ gwendall:auth-client-callbacks”。
  2. 我在所有路由的末尾添加了以下代碼。

      Accounts.onLogin(function(){ console.log(Meteor.user().profile.customerType == 'CLIENT'); // shows true if(Meteor.user().profile.customerType == 'CLIENT'){ FlowRouter.go('client'); } else { console.log('else'); } }); Accounts.onLogout(function(){ FlowRouter.go('/'); }); 

當注銷模塊運行完美時,onLogin()調用將重定向到頁面,但動作為“ FlowRouter.notFound ”。

因此,下面是我成功登錄后返回的頁面。

在此處輸入圖片說明

如何管理重定向到正確的路徑而不是“ notFound ”路徑?

- - - - - - -更新 - - - - - - -

項目\\導入\\啟動\\客戶端\\ routes.js

var clientRoutes = FlowRouter.group({
  prefix: '/client',
  name: 'client',
  triggersEnter: [function(context, redirect) {
    if(!Meteor.userId()){FlowRouter.go('/');}

    console.log('/Client route called.');
  }]
});

clientRoutes.route('/', {
  name: 'client-dashboard',
  action: function() {
    console.log("Dashboard called.");
    BlazeLayout.render('App_AuthClient', { main : 'App_UserDashboard'});
  }
});

更新

更新問題后,似乎client是FlowRouter組的名稱,而不是路由名稱,該名稱是client-dashboard ,應用於重定向用戶。


由於您使用的是FlowRouter,因此我建議采用以下方法:

  1. 創建兩個路由組:

     const protectedRoutesGroup = FlowRouter.group({ triggersEnter: [function () { if (!Meteor.userId) { FlowRouter.go('login') } }] }); const guestOnlyRoutesGroup = FlowRouter.group({ triggersEnter: [function () { if (Meteor.userId) { FlowRouter.go('homepage') } }] }); 
  2. 然后分別定義路線:

     protectedRoutesGroup.route('/', { name: 'homepage', action () { BlazeLayout.render(baseLayout, { main: 'template_name' }); } }); guestOnlyRoutesGroup.route('/', { name: 'login', action () { BlazeLayout.render(baseLayout, { main: 'login_template' }); } }); 

因此,FlowRouter將基於Meteor.userId cookie值處理重定向。

以及您被重定向到404的原因,我想可能沒有定義名稱“ client”的路由。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM