I have a problem I am new and I am trying to use React Router but it shows me a blank page whenever I use it Here is my code:
import React, {Component} from 'react';
import {BrowserRouter as Router, Route} from 'react-router-dom';
class TodoApp extends Component{
render() {
return (
<div className="TodoApp">
<Router>
<>
<Route path="/" element={<WelcomeComponent />} />
</>
</Router>
</div>
)
}
}
class WelcomeComponent extends Component{
render()
{
return <div>
abcd
</div>
}
}
If I delete the route line and instead I write somthing else the code works fine so I know I have a problem with the Route line and I am not sure what is it
Route can only be child of Routes. Try adding Routes as parent like below and you should see WelcomeComponent loading up.
render() {
return (
<div className="TodoApp">
<Router>
<Routes>
<Route path="/" element={<WelcomeComponent />} />
</Routes>
</Router>
</div>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With