forked from matthewmueller/28kb-react-redux-routing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (59 loc) · 1.22 KB
/
index.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
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
68
69
70
71
72
/**
* Module Dependencies
*/
import { render, h } from 'preact-socrates'
import History from 'redux-routes'
import Logger from 'redux-logger'
import Socrates from 'socrates'
import Route from 'enroute'
let { navigate } = History
/**
* Initialize Socrates
*
* By default, it will just store what you pass in,
* which is fine for this demo, but you'll probably
* want to use your own reducer if you're actually
* building an app
*/
let store = Socrates([
Logger(),
History()
])
/**
* App
*/
const App = (props) => (
Route({
'/blog': (params) => <Blog {...params} {...props} />,
'*': (params) => <Home {...params} {...props} />
})(props.url)
)
/**
* Home
*/
const Home = ({ dispatch, greeting }) => (
<div class='home'>
<h2>{greeting}</h2>
<button onClick={(e) => dispatch(navigate('/blog'))}>Go to the blog</button>
</div>
)
/**
* Blog
*/
const Blog = ({ dispatch }) => (
<div class='blog'>
<h2>Welcome to the Blog!</h2>
<button onClick={(e) => dispatch(navigate('/'))}>Go back to Home</button>
</div>
)
/**
* Initialize the store
*/
store('boot', {
url: document.location.pathname,
greeting: 'Welcome to the website, friend!'
})
/**
* Render
*/
render(App, store, document.body)