score:1

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
        <Routes>
          <Route exact path="/" >
            <Home />
          </Route>
          <Route path="/details" >
            <Details />
          </Route>
          <Route path="*">
            <Redirect to="/" />
          </Route>
        </Routes>

I hope this helps

score:1

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