I have been following the Learning React: A Hands-On Guide to Building Web Applications Using React and Redux book but as it is the old book so some of its syntax have been changed. Now, I am at the react router chapter and have to change old syntax to current version. The code examples of the books are as follow
JavaScript
x
21
21
1
var App = React.createClass ({
2
render : function (){
3
return (
4
<div>
5
<h1> Simple SPA </h1>
6
<ul className = "header>
7
<li> Home </li>
8
<li> Stuff </li>
9
<li> Contact </li>
10
</ul>
11
<div className = "content">
12
</div>
13
</div>
14
15
ReactDOM.render(
16
<ReactRouter.Router>
17
<ReactRouter.Route path ="/" component = {APP}>
18
</ReactRouter.Route>
19
</ReactRouter.Router>,
20
document.getElementById('app'))
21
I have tried to changed to below codes from looking tutorials but it is only rendering white screen. Please have a look at what I have done wrong here
JavaScript
1
28
28
1
class App extends React.Component{
2
render(){
3
return (
4
<div>
5
<h1> Simple SPA</h1>
6
<ul className='header'>
7
<li>Home</li>
8
<li>Stuff</li>
9
<li>Contact</li>
10
</ul>
11
<div className='content'>
12
13
</div>
14
</div>
15
)
16
}
17
}
18
ReactDOM.render(
19
<div>
20
<Router>
21
<Routes>
22
<Route path ="/" element={App}></Route>
23
</Routes>
24
</Router>
25
</div>,
26
document.getElementById('app')
27
)
28
Advertisement
Answer
Following the syntax from the quickstart example you would need to change you code a little. You need to pass the element into the <Route/>
-components as follows:
JavaScript
1
2
1
<Route path="/" element={<App />}>
2