Skip to content

Commit 330a152

Browse files
committed
updated react-router with code-splitting
1 parent 458ac16 commit 330a152

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/router.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,39 @@ import { Router, Route, IndexRoute, hashHistory } from 'react-router';
33

44
import Home from './components/Home';
55
import ArtistMain from './components/artists/ArtistMain';
6-
import ArtistDetail from './components/artists/ArtistDetail';
7-
import ArtistCreate from './components/artists/ArtistCreate';
8-
import ArtistEdit from './components/artists/ArtistEdit';
6+
7+
const componentRoutes = {
8+
component: Home,
9+
path: '/',
10+
indexRoute: { component: ArtistMain },
11+
childRoutes: [
12+
{
13+
path: 'artists/new',
14+
getComponent(location, cb) {
15+
System.import('./components/artists/ArtistCreate')
16+
.then(module => cb(null, module.default));
17+
}
18+
},
19+
{
20+
path: 'artists/:id',
21+
getComponent(location, cb) {
22+
System.import('./components/artists/ArtistDetail')
23+
.then(module => cb(null, module.default));
24+
}
25+
},
26+
{
27+
path: 'artists/:id/edit',
28+
getComponent(location, cb) {
29+
System.import('./components/artists/ArtistEdit')
30+
.then(module => cb(null, module.default));
31+
}
32+
}
33+
]
34+
};
935

1036
const Routes = () => {
1137
return (
12-
<Router history={hashHistory}>
13-
<Route path="/" component={Home}>
14-
<IndexRoute component={ArtistMain} />
15-
<Route path="artists/new" component={ArtistCreate} />
16-
<Route path="artists/:id" component={ArtistDetail} />
17-
<Route path="artists/:id/edit" component={ArtistEdit} />
18-
</Route>
19-
</Router>
38+
<Router history={hashHistory} routes={componentRoutes} />
2039
);
2140
};
2241

0 commit comments

Comments
 (0)