2

Im try to learn react routing I created a project and in my index.js file i change my code as below

import React from 'react';
import ReactDOM from 'react-dom';

import { BrowserRouter as Router, Route, Link } from 'react-router-dom';

import App from './components/App';
import Signin from './components/Signin';
import Signup from './components/Signup';

ReactDOM.render(
    <Router path="/">
        <Route path="/app" component={App} />
        <Route path="/signup" component={Signup} />                                                                    
        <Route path="/signin" component={Signin} />
    </Router>, document.getElementById('root')
);

but it gives an error like below

Module not found: Can't resolve 'react-router-dom' in 'D:\REACT\react-crud\src'

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
stewart
  • 47
  • 1
  • 8

1 Answers1

8

Install your package react-router-dom using npm install -S react-router-dom and also you can have one child for the Router. Wrap you Routes within a div/Switch whichever is suited to your needs

ReactDOM.render(
    <Router>
       <div>
        <Route path="/app" component={App} />
        <Route path="/signup" component={Signup} />                                                                    
        <Route path="/signin" component={Signin} />
       </div>
    </Router>, document.getElementById('root')
);
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400