当前位置: 首页 > 知识库问答 >
问题:

警告:失败的道具类型:为'Route'提供的'object'类型的无效道具'component',应为'function'`

聂风史
2023-03-14

这是什么错误???

我得到了旧的工作代码,安装了新版本的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>
        )
    }
}

这是什么错误?我的代码怎么了?已安装路由器dom@^4.1。0:

共有1个答案

吕骞尧
2023-03-14

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

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

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

 类似资料: