Accepted answer

Try using Routes instead of switch.

  1. import Routes
import { BrowserRouter , Redirect, Route , Routes, Switch } from 'react-router-dom';

  1. Change the Switch to *Routes
          <Route exact path="/" >
            <Home />
          <Route path="/details" >
            <Details />
          <Route path="*">
            <Redirect to="/" />

I hope this helps


Upgrade to React-router-dom: Version: 5.3.3 because Version: 5.1 has bug.

1.Uninstall whatever version you are having npm uninstall -s react-router-dom@5.1 npm uninstall -s react-router-dom

2.Install React-router-dom: Version: 5.3.3 npm install -s react-router-dom@5.3.3

Or go to this post: Click Me to go to Post

Related Query

More Query from same tag