I Am Getting This Error Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it
And
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.
This One
App.js file is
import React, { Component } from 'react';
import HomePage from './pages/HomePage';
import { BrowserRouter, Routes, Route, } from 'react-router-dom';
import './App.css';
import { render } from '@testing-library/react';
class App extends Component { render() {
return (
<BrowserRouter>
<Routes>
<Route path='/' element={HomePage} exact/>
</Routes>
</BrowserRouter>
); } }
export default App;
And Homepage.js
import React from 'react';
const HomePage = () => (
<>
<h1>Hello, welcome to my blog!</h1>
<p>
Welcome to my blog! Proin congue
ligula id risus posuere, vel eleifend ex egestas. Sed in turpis leo.
Aliquam malesuada in massa tincidunt egestas. Nam consectetur varius turpis,
non porta arcu porttitor non. In tincidunt vulputate nulla quis egestas. Ut
eleifend ut ipsum non fringilla. Praesent imperdiet nulla nec est luctus, at
sodales purus euismod.
</p>
<p>
Donec vel mauris lectus. Etiam nec lectus urna. Sed sodales ultrices dapibus.
Nam blandit tristique risus, eget accumsan nisl interdum eu. Aenean ac accumsan
nisi. Nunc vel pulvinar diam. Nam eleifend egestas viverra. Donec finibus lectus
sed lorem ultricies, eget ornare leo luctus. Morbi vehicula, nulla eu tempor
interdum, nibh elit congue tellus, ac vulputate urna lorem nec nisi. Morbi id
consequat quam. Vivamus accumsan dui in facilisis aliquet.,
</p>
<p>
Etiam nec lectus urna. Sed sodales ultrices dapibus.
Nam blandit tristique risus, eget accumsan nisl interdum eu. Aenean ac accumsan
nisi. Nunc vel pulvinar diam. Nam eleifend egestas viverra. Donec finibus lectus
sed lorem ultricies, eget ornare leo luctus. Morbi vehicula, nulla eu tempor
interdum, nibh elit congue tellus, ac vulputate urna lorem nec nisi. Morbi id
consequat quam. Vivamus accumsan dui in facilisis aliquet.,
</p>
</>
);
export default HomePage;
CodePudding user response:
Replace <Route path='/' element={HomePage} exact/>
with <Route path='/' element={<HomePage/>} exact/>
.
You need to pass it as an element and not as a prop since react router v6.