-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
35 lines (26 loc) · 897 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { createBrowserHistory } from 'history'
import React, { useEffect, useState } from 'react'
import NotFound from 'routes/404'
import Landing from 'routes/landing'
import Privacy from 'routes/privacy'
import Thanks from 'routes/thanks'
import normalizePathname from 'utils/normalizePathname'
const history = createBrowserHistory()
const navigate = path => history.push(path)
function getRoute(location) {
switch (normalizePathname(location.pathname)) {
case '/':
return <Landing navigate={navigate} />
case '/privacy':
return <Privacy navigate={navigate} />
case '/thanks':
return <Thanks navigate={navigate} />
default:
return <NotFound navigate={navigate} />
}
}
export default function App() {
const [location, setLocation] = useState(history.location)
useEffect(() => history.listen(setLocation), [])
return getRoute(location)
}