当注册表作为组件传递给路线

时间:2019-06-10 10:51:40

标签: reactjs

我有一个名为Register.js的文件,其中包含ant design的注册表格,当我通过App.js中的路线时,出现以下错误:

Uncaught Invariant Violation: Element type is invalid:
expected a string (for built-in components) or a class/function (for composite components) but got:undefined.
You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `RegistrationForm`.

稍作修改的Register.js。修改之处在于,不是直接渲染,而是使用export default WrappedRegistrationForm;

导出它

我正在导入,然后在App.js中如下使用它:

import WrappedRegistrationForm from './components/Onboard';

<Route                                           
   exact                                             
   path="/register"                                          
   component={WrappedRegistrationForm}/>

Onboardcomponents内的一个文件夹,其中包含Register.jsindex.js

Onboard/
    Register.js
    index.js

其中index.js文件只是从Register.js导入组件并将其导出。

Onboard/index.js

import WrappedRegistrationForm from './Register';

export default WrappedRegistrationForm;

如何在访问路线Register.js时成功呈现/register

0 个答案:

没有答案