Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React JS Error – No routes matched location "/"

It show white screen and console error ( No routes matched location "/" )

import {BrowserRouter as Router, Switch, Routes, Link} from 'react-router-dom'; 
import Home from './pages/Home';
import About from './pages/About';

function App(){
    return <>
            

            <Router>
            <Link to="/">Home</Link> 
            <Link to="/About">About</Link>

                <Routes path={'/'} elements={<Home />}  />
                <Routes path={'/About'} elements={<About />} />
            </Router>       
    </>;
}

export default App;

Please Help me. Thanx in Advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this:

import {
  BrowserRouter as Router,
  Routes,
  Route,
  Link
} from "react-router-dom";
import Home from "./pages/Home";
import About from "./pages/About";

function App() {
  return (
    <>
      <Router>
        <Link to="/">Home</Link>
        <Link to="/About">About</Link>

        <Routes>
          <Route index element={<Home />} />
          <Route path="About" element={<About />} />
        </Routes>
      </Router>
    </>
  );
}

export default App;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading