Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit e4d6044

Browse files
committed
examples menu now gets created dynamically
1 parent 4a5871e commit e4d6044

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

examples/index.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import {HashRouter, Switch, Route, Link} from 'react-router-dom';
3+
import {HashRouter, Link, Route, Switch} from 'react-router-dom';
44

55
import Home from './Home';
66
import Login from './Login';
77

8+
const menuEntries = [
9+
{
10+
exact: true,
11+
path: '/',
12+
component: Home,
13+
text: 'Home'
14+
},
15+
{
16+
path: '/login',
17+
component: Login,
18+
text: 'Login'
19+
}
20+
];
21+
822
ReactDOM.render(
923
<HashRouter>
1024
<div>
1125
<nav>
1226
<ul>
13-
<li><Link to='/'>Home</Link></li>
14-
<li><Link to='/login'>Login</Link></li>
27+
{menuEntries.map((entry, index) => {
28+
let replace = entry.path === window.location.hash.replace('#', '');
29+
return <li key={index}><Link to={entry.path} replace={replace}>{entry.text}</Link></li>;
30+
})}
1531
</ul>
1632
</nav>
1733
<main>
1834
<Switch>
19-
<Route exact path='/' component={Home}/>
20-
<Route path='/login' component={Login}/>
35+
{menuEntries.map((entry, index) => {
36+
return <Route key={index} exact={!!entry.exact} path={entry.path} component={entry.component}/>;
37+
})}
2138
</Switch>
2239
</main>
2340
</div>

0 commit comments

Comments
 (0)