[英]React.createElement error using ReduxRouter
I'm trying to use redux-router in a project, but I cannot get it to work. 我正在尝试在项目中使用redux-router,但无法使其正常工作。
Here is my routes definition (partial) : 这是我的路线定义(部分):
export default function(store) {
return (
<Route path="/" component={Main}>
[ALL NESTED ROUTES]
</Route>
)
}
My routes work well with react-router. 我的路线与react-router配合良好。
And then my init code (partial) : 然后是我的初始化代码(部分):
import ReduxRouter from 'redux-router'
import {Provider} from 'react-redux'
[...]
const routes = Routes(store);
class Root extends Component {
render() {
return (
<div>
<Provider store={store}>
<ReduxRouter>{routes}</ReduxRouter>
</Provider>
</div>
);
}
}
ReactDOM.render(<Root />, document.getElementById('content'));
I get the following error on the ReduxRouter's createElement : 我在ReduxRouter的createElement上收到以下错误:
Warning: React.createElement: type should not be null, undefined, boolean, or number.
警告:React.createElement:type不能为null,undefined,boolean或number。 It should be a string (for DOM elements) or a ReactClass (for composite components).
它应该是一个字符串(对于DOM元素)或一个ReactClass(对于复合组件)。
I get the following error if I just try to write to console : 如果我只是尝试写入控制台,则会出现以下错误:
<ReduxRouter>{routes}</ReduxRouter>
In the console, I get a Symbol(react.element)
with correct props (my routes as children), but with type undefined
在控制台中,我得到一个
Symbol(react.element)
带有正确的道具(我的路线为子代),但类型为undefined
As a consequence, I then get : 结果,我得到:
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
未捕获的不变违规:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。 Check the render method of
Root
.检查
Root
的渲染方法。
What am I missing ? 我想念什么?
OK, that was a stupid one. 好,那是一个愚蠢的人。 I was just importing ReduxRouter incorrectly.
我只是错误地导入了ReduxRouter。
Correct import is : 正确的导入是:
import { ReduxRouter } from 'redux-router'
Thanks to @tomo from Reactiflux for pointing that out ! 感谢Reactiflux的@tomo指出这一点!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.