我正在使用路由器制作react应用程序,但出现以下错误:
react类型错误:WEBPACK_IMPORTED_MODULE_0_react .PropTypes 未定义
我怎样才能避免它?
这里是 2 个路由器的代码,post 和 profile:
帖子
import React,{Component} from 'react';
class Posts extends Component{
render(){
return <div> Posts </div>
}
}
export default Posts;
轮廓
import React,{Component} from 'react';
class Profile extends Component{
render(){
return <div> Profile </div>
}
}
export default Profile;
索引.js
import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter, Route} from 'react-router-dom';
import PropTypes from 'prop-types';
//COMPONENTS
import Posts from './Components/posts';
import Profile from './Components/profile';
class App extends Component{
render(){
return <div> home </div>
}
}
ReactDOM.render(
<BrowserRouter>
<div>
<Route path="/posts" component={Posts}> </Route>
<Route path="/profile" component={Profile}> </Route>
</div>
</BrowserRouter>
,document.querySelector('#root'))
这是错误的屏幕截图: