我有一个名为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}/>
Onboard
是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
。