2017-08-02 50 views
0

对象作为React子项无效。如果您打算渲染一组儿童,请改用数组,或者使用React附加组件中的createFragment(object)来包装对象。检查Root的渲染方法。“对象作为React子项无效”仅在IE中出现

这一问题只出现在IE浏览器,我知道一个孩子的反应不能是一个对象,但我不能找到根类的任何错误

// Root.js 
import React, { Component, PropTypes } from 'react' 
import { Provider } from 'react-redux' 
import { Router, browserHistory } from 'react-router' 
import { syncHistoryWithStore } from 'react-router-redux' 
import routes from './routes' 

export default class Root extends Component { 
    render() { 
    const { store } = this.props 


    const history = syncHistoryWithStore(browserHistory, store) 

    return (
     <Provider store={store}> 
     <div> 
      <Router history={history} routes={routes} /> 
     </div> 
     </Provider> 
    ) 
    } 
} 



// routes.js 

import React from 'react' 
import { Route } from 'react-router' 

import Cookie from './libs/cookie' 
import App from './app' 
import MobileRouter from './routes/mobile' 
import WebRouter from './routes/web' 

export default (
    <Route path="/" component={App}> 
    { WebRouter } 
    { MobileRouter } 
    </Route> 
) 



// App.js 

import React, { Component, PropTypes } from 'react' 
import { connect } from 'react-redux' 
import { browserHistory } from 'react-router' 

class App extends Component { 
    constructor(props) { 
    super(props) 
    } 

    render() { 
    const { children } = this.props 

    return (
     <div> 
     { children } 
     </div> 
    ) 
    } 
} 
+0

请显示'routes'组件。 – Andrew

+0

我已添加路由添加应用组件代码 –

+0

我认为问题在这里,{WebRouter} {MobileRouter}'。什么是“MobileRouter”和“WebRouter”? – Andrew

回答

0

“的对象是不能作为有效反应子“只出现在IE中

不正确。如果您使用对象,则此错误将出现在所有浏览器中。你最有可能有类似于下面的东西在你的代码

{someBool && someObj} 

其中someBool仅现身真正基于应用程序的状态是如何在IE浏览器。如果您在任何其他浏览器中执行了相同的操作,您将得到相同的错误。

修复

不要渲染object。 React无法处理它。并且正在给你正确的错误,你应该修复它,例如从obj中渲染一些东西,例如

{someBool && someObj.someStringProp} 
相关问题