【问题标题】:Fetch from collection on visiting route using FlowRouter doesn't work on page reload使用 FlowRouter 从访问路线的集合中获取在页面重新加载时不起作用
【发布时间】:2016-05-22 08:39:40
【问题描述】:

我在 Meteor + React 应用程序中定义了一条路线,如下所示。我想获取帖子并通过道具传递给组件。但是当我在该 URL 上重新加载页面时,我收到一条错误消息,说帖子未定义。当我从网站的其他部分访问时,我可以访问该 URL,但在重新加载时不能访问。

const Posts = new Mongo.Collection('posts');

FlowRouter.route('/post/:slug', {
  name: 'Post.show',
  action(params) {
    let post = Posts.findOne({slug: params.slug});
    mount(Layout, {
      main: () => <Post key={post._id} post={post} />,
    });
  },
});

也许这不是要走的路,但我希望能够传递自定义帖子,这就是我使用这种方法的原因。是否与 Posts 集合未完全启动有关?如果是,我该如何等待它启动?

【问题讨论】:

    标签: mongodb meteor flow-router meteor-react mongo-collection


    【解决方案1】:

    Posts 可能在您重新加载页面并执行路由操作时为空。取而代之的是,您应该使用 createContainer 创建一个响应式组件。

    https://www.meteor.com/tutorials/react/collections

    【讨论】:

      猜你喜欢
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 2016-12-26
      • 1970-01-01
      • 2017-11-11
      • 2016-12-22
      • 2011-09-14
      相关资源
      最近更新 更多