首页 > 解决方案 > 注册表单作为组件传递给路由时出错

问题描述

我有一个名为Register.js包含 ant design 的注册表单的文件,当我传递给 Route in 时,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;

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

import WrappedRegistrationForm from './components/Onboard';

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

这是一个包含andOnboard的文件夹。componentsRegister.jsindex.js

Onboard/
    Register.js
    index.js

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

Onboard/index.js

import WrappedRegistrationForm from './Register';

export default WrappedRegistrationForm;

如何Register.js在访问路线时成功渲染/register

标签: reactjs

解决方案


推荐阅读