npm install react-router-dom --save
// src > core-parts > navbar.jsx import React, { Component } from 'react' import { Link } from "react-router-dom"; class Navbar extends Component { render() { return ( <ul> <li> <Link to="/">Home</Link> </li> <li className="nav-item"> <Link to="/about">About</Link> </li> <li className="nav-item"> <Link to="/contact">Contact US</Link> </li> </ul> ) } } export default Navbar
// src > core-parts > router.jsx import React, { Component } from 'react' import { BrowserRouter as Router, Route, } from "react-router-dom"; import Home from '../components/home'; import About from '../components/about'; import ContactUS from '../components/contactus'; import Navbar from './navbar'; class AppRoute extends Component { render() { return ( <div> <Router> <Navbar></Navbar> <div> <Route exact path="/" component={Home} /> <Route path="/about" component={About} /> <Route path="/contact" component={ContactUS} /> </div> </Router> </div> ) } } export default AppRoute
import React from 'react'; import './App.css'; import AppRoute from './core-part/router'; function App() { return ( <AppRoute></AppRoute> ); } export default App;