Setup React Router

Need React web app to setup react-router.

If you don't know how to setup, open my previous article about setup react app it will help you to setup.


After successfully setup react project follow below steps to setup react-router

Using npm

npm i react-router-dom --save

Using yarn

yarn add react-router-dom

Basic Example

configure your app component like below example.

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

const Home = () => (

const Dashboard = () => (

const Login = () => (

const AppRouter = () => (
            <Link to="/home">Home</Link>
            <Link to="/dashboard/">Dashboard</Link>
            <Link to="/login/">Login</Link>

      <Route path="/" exact component={Home} />
      <Route path="/home" exact component={Home} />
      <Route path="/dashboard/" component={Dashboard} />
      <Route path="/login/" component={Login} />

export default AppRouter;

for more detail and for more examples follow here