OSDN Git Service

add translation to page title.
[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     name_zh: options.name_zh,
42     indexRoute: {
43       component: List,
44       onEnter: (nextState, replace) => {
45         loadPage(nextState, replace)
46       },
47       onChange: (_, nextState, replace) => { loadPage(nextState, replace) }
48     },
49     childRoutes: childRoutes
50   }
51 }
52
53 export default makeRoutes