as you may get from the title, passing props in react is not working. And i don´t get why.
JavaScript
x
10
10
1
import styled from 'styled-components';
2
3
4
const Login = (props) => {
5
return<div>Login</div>
6
7
}
8
9
export default Login;
10
On my App.js page here is the following:
JavaScript
1
20
20
1
import './App.css';
2
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
3
import Login from './components/Login.js';
4
5
function App() {
6
return (
7
<div className="App">
8
<Router>
9
<Routes>
10
<Route exact path="/" >
11
<Login />
12
</Route>
13
</Routes>
14
</Router>
15
</div>
16
);
17
}
18
19
export default App;
20
Problem: if i start the script and render the page, nothing is shown. What am I doing wrong?
Advertisement
Answer
You should pass <Login />
as the element. Try this code:
App.js:
JavaScript
1
18
18
1
import './App.css';
2
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
3
import Login from './components/Login.js';
4
5
function App() {
6
return (
7
<div className="App">
8
<Router>
9
<Routes>
10
<Route exact path="/" element={<Login />} />
11
</Routes>
12
</Router>
13
</div>
14
);
15
}
16
17
export default App;
18