reactjs - 注册表单作为组件传递给路由时出错
问题描述
我有一个名为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
的文件夹。components
Register.js
index.js
Onboard/
Register.js
index.js
index.js 文件只是从中导入组件Register.js
并将其导出。
Onboard/index.js
import WrappedRegistrationForm from './Register';
export default WrappedRegistrationForm;
如何Register.js
在访问路线时成功渲染/register
。
解决方案
推荐阅读
- php - Laravel 8:尝试删除用户时出现 404“未找到”页面
- python - 如何用 seaborn 绘制 pandas 三列(用 group by 计算)
- aws-api-gateway - 通过 AWS ApiGateway 限制客户端对特定 DynamoDB 表的访问
- php - 如何使正则表达式过滤掉php laravel 8中url的特定单词?
- c# - Xamarin Shell android 使用 xml 标记进行自定义
- python - 可视化库的建议
- ruby-on-rails - 与 Apartment gem 一起使用时,向 ActiveStorage 资源发出请求偶尔会失败
- c# - Blazor 在有条件的 div 包装器上关闭 div 标记
- jquery - 为暗模式添加本地存储(在 jquery 中)
- amazon-web-services - 根据列在s3中拆分csv文件