-
-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathapp.js
More file actions
67 lines (58 loc) · 1.59 KB
/
app.js
File metadata and controls
67 lines (58 loc) · 1.59 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { h } from 'preact'
import { Router } from 'preact-router'
import { useEffect } from 'preact/hooks'
import analytics from './analytics'
import Header from './components/header'
// Code-splitting is automated for routes
import Home from './routes/home'
import About from './routes/about'
import Dashboard from './routes/dashboard'
import DashboardItem from './routes/dashboardItems'
import Profile from './routes/profile'
import NotFound from './routes/NotFound'
import Login from './routes/login'
import PrivateRoute from './routes/PrivateRoute'
const inBrowser = typeof window !== "undefined"
// Set login false for demo
if (inBrowser) {
window.isLoggedIn = false
}
export default function App() {
useEffect(() => {
analytics.on('pageEnd', ({ payload }) => {
console.log('pageView fired from analytics', payload.properties)
})
}, [])
/** Gets fired when the route changes.
* @param {Object} event "change" event from [preact-router](http://git.io/preact-router)
* @param {string} event.url The newly routed URL
*/
const handleRoute = e => {
if (inBrowser) {
analytics.page()
}
}
return (
<div id="app">
<Header />
<Router onChange={handleRoute}>
<Home path='/' />
<About path='/about' />
<Login path="/login" />
<PrivateRoute
path="/dashboard"
component={() => <Dashboard />}
/>
<PrivateRoute
path="/dashboard/:id"
component={(p) => <DashboardItem {...p} />}
/>
<PrivateRoute
path="/dashboard/profile"
component={() => <Profile user="me" />}
/>
<NotFound type="404" default />
</Router>
</div>
)
}