I have a app created from create-react-app and the prop location for all my components is always undefined..
Here is index.js
ReactDOM.render((
<BrowserRouter >
<App/>
</BrowserRouter>
), document.getElementById('root'));
registerServiceWorker();
Here is a short version of app.js
import {BrowserRouter as Router, Route, Switch} from 'react-router-dom';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
auth: UserProfile.getAuth(),
}
}
render() {
if(this.state.auth){
return (
<Router>
<Switch>
...
<Route path="/editUser" render={()=><EditUser className="App" app={this}/>} />
</Switch>
</Router>
);
}
else{
...
}
}
}
now here is editUser.jsx
class EditUser extends React.Component {
constructor(props) {
super(props);
...
}
componentDidMount(){
console.log(this.props.location) //undefined
}
render() {
return (<div>...</div>)
I keep getting undefined and I dont understand why...
I use "react-router-dom": "^4.3.1"
according to my package.json
Please help!