This repository was archived by the owner on Feb 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
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' ;
4
4
5
5
import Home from './Home' ;
6
6
import Login from './Login' ;
7
7
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
+
8
22
ReactDOM . render (
9
23
< HashRouter >
10
24
< div >
11
25
< nav >
12
26
< 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
+ } ) }
15
31
</ ul >
16
32
</ nav >
17
33
< main >
18
34
< 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
+ } ) }
21
38
</ Switch >
22
39
</ main >
23
40
</ div >
You can’t perform that action at this time.
0 commit comments