OSDN Git Service

remove console.log
[bytom/bytom-electron.git] / src / features / shared / routes.js
1 import { RoutingContainer } from 'features/shared/components'
2 import { humanize } from 'utility/string'
3 import actions from 'actions'
4
5 const makeRoutes = (store, type, List, New, Show, Update, options = {}) => {
6   const loadPage = () => {
7     store.dispatch(actions[type].fetchAll())
8   }
9
10   const childRoutes = []
11
12   if (New) {
13     childRoutes.push({
14       path: 'create',
15       component: New
16     })
17   }
18
19   if (options.childRoutes) {
20     childRoutes.push(...options.childRoutes)
21   }
22
23   if (Show) {
24     childRoutes.push({
25       path: ':id',
26       component: Show
27     })
28   }
29
30   if (Update) {
31     childRoutes.push({
32       path: ':id/tags',
33       component: Update
34     })
35   }
36
37   return {
38     path: options.path || type + 's',
39     component: RoutingContainer,
40     name: options.name || humanize(type + 's'),
41     indexRoute: {
42       component: List,
43       onEnter: (nextState, replace) => {
44         loadPage(nextState, replace)
45       },
46       onChange: (_, nextState, replace) => { loadPage(nextState, replace) }
47     },
48     childRoutes: childRoutes
49   }
50 }
51
52 export default makeRoutes