Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matched leaf route at location "/" does not have an element

Matched leaf route at location "/" does not have an element. This means it will render an with a null value by default resulting in an "empty" page

//App.js File

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


const App = () => {
  return (

    <Router >
      <Routes>

        <Route path="/" component={ Home }></Route>
      </Routes>
    </Router>


  )
}

export default App;

**My any react router related code not working i don't know why it happend when i start insert some route in program so it show this error **

like image 739
user16102215 Avatar asked Nov 05 '21 13:11

user16102215


People also ask

Does not have an element This means it will render an?

Matched leaf route at location "/" does not have an element. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page. Your project has react-router-dom version 6. In version 6, you will need to replace component prop with element prop within your route.

Which element tries to match its path to the current history location?

A <Route> element tries to match its path to the current history location (usually the current browser URL). However, a location with a different pathname can also be passed for matching.

What is exact in react router?

The exact param disables the partial matching for a route and makes sure that it only returns the route if the path is an EXACT match to the current url.


2 Answers

In V6, you can't use the component prop anymore. It was replaced in favor of element:

<Route path="/" element={<Home />}></Route>

More info in the migration doc.

like image 120
tavoyne Avatar answered Oct 17 '22 17:10

tavoyne


I had the same problem. Replace component with element and it worked.

Replace this:

<Route path="/" component={HomePage} exact />

with this:

<Route path="/" element={<HomePage/>} exact />
like image 50
Anita Jayana Avatar answered Oct 17 '22 17:10

Anita Jayana