Reputation: 374
I have used create-react-app for creating a new working repository for react and i wanted to add some Routing paths using react-router-dom.
This is my index.js file.
import React from 'react';
import ReactDOM from 'react-dom';
import PostsIndex from './components/posts_index';
import {BrowserRouter,Switch,Route} from 'react-router-dom';
ReactDom.render(
<BrowserRouter>
<div>
<Switch>
<Route path="/" component={PostsIndex} />
</Switch>
</div>
</BrowserRouter>,
document.getElementById('root')
);
And this is my posts_index.js file
import React,{Component} from 'react';
class PostsIndex extends Component {
render(){
return(
<div>Posts Index </div>
)
}
export default PostsIndex;
Can someone help me with this error?
Upvotes: 0
Views: 1067
Reputation: 430
This was how I fixed this particular error at my end.
yarn add react-router-dom --save
yarn start
And away the error went. If you use npm
for dependency management, I believe the same should apply while replacing yarn
with npm
.
Upvotes: 1
Reputation: 3102
Seems to be working on my end.
Only things I had to adjust was the ReactDom
to ReactDOM
and a missing closing parenthesis in posts_index.js
Working solution: https://codesandbox.io/s/nkvjqrvpwj
Upvotes: -1