为什么在myor.js应用程序中使用react时不包含separete .jsx文件

时间:2015-11-06 14:59:17

标签: node.js meteor reactjs flow-router meteor-react

我一直在使用流星反应和流路由器处理meteor.js和react.js应用程序。

我开始使用这样的结构:

  • 客户端
    • 部件
      • register.jsx
    • 布局
      • header.jsx
      • footer.jsx
    • LIB
      • router.jsx main.html中 main.jsx

在我的router.jsx文件中,我从register.jsx文件中调用RegisterForm类

FlowRouter.route('/', {
    action() {
        ReactLayout.render(MainLayout, { content: <RegistrationForm /> });
    }

});

只要我的所有组件类都在register.jsx文件中,但是随着我的项目变得越来越大,而不是将所有类放在单个文件中,我想将register.jsx拆分成单独的.jsx文件,这种方法很有效。

例如,我有一个名为VerifiedInput的类,它包含用于输入字段的自定义验证的额外功能。如果我在同一个register.jsx中包含这个类,我可以在我的RegisterForm类的render函数中调用它,

VerifiedInput = React.createClass({
    ....
});

RegistrationForm = React.createClass({
   ....    
   render : function(){
       return(
           <VerifiedInput />
        )
    }
});

但如果我将VerifiedInput类移动到单独的文件中,那么我的组件文件夹结构将更改为:

- components
   - register.jsx
   - validinput.jsx

然后我收到错误: ReferenceError:未定义VerifiedInput

这似乎表明没有包含.jsx文件。

正如我所说,流星应该自动包含客户端文件夹中的文件,并且无法使用 require() Meteor.js

如何确保包含单独文件中的反应类?

0 个答案:

没有答案