首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FlowRouter on Account.onLogin()不能在Meteor中正确地重定向

FlowRouter on Account.onLogin()不能在Meteor中正确地重定向
EN

Stack Overflow用户
提问于 2017-05-16 12:37:17
回答 1查看 266关注 0票数 0

我所有的路线运行良好,我的路线在"D:\test\imports\startup\client\routes.js".中声明。

  1. 我添加了一个包“gwendall:auth-client-回调”。
  2. 我在所有路线的末尾添加了下面的代码。 函数(函数(){ console.log(Meteor.user().profile.customerType == 'CLIENT');//显示真if(Meteor.user().profile.customerType == 'CLIENT'){ FlowRouter.go('client');}Meteor.user{console.log(‘Meteor.user’);};Accounts.onLogout(函数(){ FlowRouter.go('/');});

当注销模块完美运行时,onLogin()调用重定向到页面,但使用"FlowRouter.notFound“操作。

下面是我成功登录时返回的页面。

怎样才能重定向到正确的路径而不是'notFound‘路径?

-------------UPDATED-------------

PROJECT\imports\startup\client\routes.js

代码语言:javascript
复制
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'});
  }
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-17 12:05:45

更新

在更新了问题后,出现了client是FlowRouter组的名称,而不是路由名,它是client-dashboard,应该用于重定向用户。

由于您使用的是FlowRouter,所以我建议采用以下方法:

  1. 创建两个路由组: const protectedRoutesGroup = FlowRouter.group({ triggersEnter: function () { if (!Meteor.userId) {FlowRouter.go(‘FlowRouter.go’) });const guestOnlyRoutesGroup = FlowRouter.group({ triggersEnter: function () { if (Meteor.userId) { FlowRouter.go('homepage') } });
  2. 然后分别定义您的路线: protectedRoutesGroup.route('/',{ name:‘主页’,action () { BlazeLayout.render(baseLayout,{ main:'template_name‘});});guestOnlyRoutesGroup.route('/',{ name:’登录‘,action () { BlazeLayout.render(baseLayout,{ main:'login_template’});});

因此,FlowRouter将处理基于Meteor.userId cookie值的重定向。

而您被重定向到404的原因是,我想没有定义名称"client“的路由。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44001688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档