警告:失败的道具类型:提供给`Route`的类型`object`的无效prop`组件`,期望的`function`

时间:2017-04-13 15:56:37

标签: reactjs react-router-v4

这是错误???

我得到旧的工作代码安装新版本的libs,我看到了这个错误。但我无法理解它的含义。

//index.js
import React from 'react'
import {render} from 'react-dom'
import { BrowserRouter as Router } from 'react-router-dom'
import {Provider} from 'react-redux'
import configureStore, {history} from './store/configureStore'
import {routes} from './routes'
import { ConnectedRouter, routerMiddleware, push } from 'react-router-redux'

const store = configureStore();

render(
    <Provider store={store}>
        <Router history={history} routes={routes}/>
    </Provider>,
    document.getElementById('app')
);

//routes.js
import React from 'react'
import {Route} from 'react-router-dom'
import App from './containers/App'

export const routes = (
    <div>
        <Route path='/' component={App} />
    </div>
);

//App.js
import React, {Component} from 'react'
import NavLink from '../../components/NavLink'

export default class App extends Component {
    render() {
        return (
            <div className='container'>
                <ul className='nav nav-pills'>
                    <li>
                        <NavLink onlyActiveOnIndex={true} to='/'>Главная</NavLink>
                    </li>
                </ul>
                {this.props.children}
            </div>
        )
    }
}

这是什么错误?我的代码有什么问题? 安装react-router-dom@^4.1.0:

1 个答案:

答案 0 :(得分:1)

只是强迫它成为一个函数,因为道具期望它摆脱控制台错误,即使这不是理想的解决方案。

<Route path='/' component={props => <App {...props} />} />

https://github.com/ReactTraining/react-router/issues/6420#issuecomment-433541079