[英]Electron - React.createElement: type is invalid error
I have just created a React application built on Electron and am trying to implement react-router
. 我刚刚创建了一个基于Electron的React应用程序,并且正在尝试实现react-router
。 After much research and a couple hours of headache I am unable to correct this error the Electron Chrome console is presenting me with: 经过大量研究和几个小时的头痛之后,我无法纠正此错误,Electron Chrome控制台向我显示:
bundle.js:1426 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. bundle.js:1426警告:React.createElement:类型无效-预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。 You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. 您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。
Without react-router
I am able to render components just like any other React application. 没有react-router
我可以像其他任何React应用程序一样呈现组件。 Here is my code: 这是我的代码:
index.js index.js
import React, { Component } from 'react';
import { render } from 'react-dom';
import { Router, Route, IndexRoute } from 'react-router';
import createHashHistory from 'history/createHashHistory';
import App from './containers/App';
import Login from './containers/Login';
const routes = (
<Route path="/" component={App}>
<IndexRoute component={Login} />
</Route>
);
const MOUNT_NODE = document.getElementById('app');
render(
<Router history={createHashHistory()} routes={routes} />,
MOUNT_NODE
);
containers/App.js 容器/App.js
import React, { Component, PropTypes } from 'react';
export default class AppContainer extends Component {
constructor(props) {
super(props);
this.props.children = PropTypes.element.isRequired;
}
render() {
return (
<div>
{this.props.children}
</div>
);
}
}
containers/Login.js container / Login.js
import React, { Component } from 'react';
import Login from '../components/Login';
export default class LoginContainer extends Component {
render() {
return (
<Login />
);
}
}
components/Login.js 组件/Login.js
import React, { Component } from 'react';
export default class Login extends Component {
render() {
return (
<div>
<h1>Login Component</h1>
</div>
);
}
}
Any ideas on how to remove the quoted error? 关于如何消除引用错误的任何想法? Thanks in advance. 提前致谢。
What version of React Router are you using? 您正在使用哪个版本的React Router? Have you tried to import from react-router-dom instead of react-router? 您是否尝试过从react-router-dom而不是react-router导入?
import { Router, Route, IndexRoute } from 'react-router-dom';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.