/
routes.js
62 lines (59 loc) · 1.47 KB
/
routes.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
/**
* This file handles all routing and async loading of
* split JavaScript files. The splitting of components
* is based off the routes created in this file.
*/
import Core from './components/Core';
// throws an error in the console of the page wasn't able to load
function errorLoading(error) {
throw new Error(`Dynamic page loading failed: ${error}`);
}
function loadRoute(cb) {
return module => cb(null, module.default);
}
/**
* This object we are exporting is the equivalent of:
* <Route path="/" component={Core}>
* <IndexRoute component={Home}/>
* <Route path="about" component={About}/>
* <Route path="users" component={Users}>
* <Route path="*" component={Home}/>
* </Route>
*/
export default {
path: '/',
component: Core,
indexRoute: {
getComponent(location, cb) {
System.import('./components/Home')
.then(loadRoute(cb))
.catch(errorLoading);
},
},
childRoutes: [
{
path: 'about',
getComponent(location, cb) {
System.import('./components/About')
.then(loadRoute(cb, false))
.catch(errorLoading);
},
},
{
path: 'users',
getComponent(location, cb) {
System.import('./components/Users')
.then(loadRoute(cb))
.catch(errorLoading);
},
},
{
path: '*',
getComponent(location, cb) {
System.import('./components/Home')
.then(loadRoute(cb))
.catch(errorLoading);
},
},
],
};