Browse Source

Route are now declared in a safer way

Skylsmoi 6 years ago
parent
commit
846d5611b6
3 changed files with 12 additions and 11 deletions
  1. 3 3
      src/container/Tracim.jsx
  2. 1 0
      src/container/WorkspaceContent.jsx
  3. 8 8
      src/helper.js

+ 3 - 3
src/container/Tracim.jsx View File

@@ -58,10 +58,10 @@ class Tracim extends React.Component {
58 58
               <Route path={PAGE.LOGIN} component={Login} />
59 59
 
60 60
               <PrivateRoute exact path={PAGE.HOME} component={WorkspaceContent} />
61
-              <PrivateRoute exact path={PAGE.WORKSPACE.CONTENT_LIST(':idws')} component={WorkspaceContent} /> {/* "exact" here to not double match Route WORKSPACE.CONTENT */}
62
-              <PrivateRoute path={PAGE.WORKSPACE.CONTENT(':idws', ':idcts')} component={WorkspaceContent} />
61
+              {/* bellow, the '?' is important, it avoid to have to declare another route for CONTENT_LIST which could double match */}
62
+              <PrivateRoute path={PAGE.WORKSPACE.CONTENT(':idws', ':idcts?')} component={WorkspaceContent} />
63 63
               <PrivateRoute path={PAGE.ACCOUNT} component={Account} />
64
-              <PrivateRoute path={PAGE.WORKSPACE.DASHBOARD(':idws')} component={Dashboard} />
64
+              <PrivateRoute path={PAGE.WORKSPACE.DASHBOARD()} component={Dashboard} />
65 65
               <PrivateRoute path={'/wip/:cp'} component={WIPcomponent} /> {/* for testing purpose only */}
66 66
 
67 67
               <Footer />

+ 1 - 0
src/container/WorkspaceContent.jsx View File

@@ -21,6 +21,7 @@ const qs = require('query-string')
21 21
 
22 22
 class WorkspaceContent extends React.Component {
23 23
   async componentDidMount () {
24
+    console.log('WorkspaceContent did mount')
24 25
     const { workspaceList, app, match, location, dispatch } = this.props
25 26
 
26 27
     if (Object.keys(app).length === 0) await dispatch(getAppList())

+ 8 - 8
src/helper.js View File

@@ -10,15 +10,15 @@ export const FETCH_CONFIG = {
10 10
 export const PAGE = {
11 11
   HOME: '/',
12 12
   WORKSPACE: {
13
-    DASHBOARD: idws => `/workspace/${idws}`,
13
+    DASHBOARD: (idws = 'idws') => `/workspace/${idws}`,
14 14
     NEW: '/workspace/new',
15
-    CALENDAR: idws => `/workspace/${idws}/apps/calendar`,
16
-    CONTENT_LIST: idws => `/workspace/${idws}/apps/contents`,
17
-    CONTENT: (idws, idcts) => `/workspace/${idws}/apps/contents/${idcts}`,
18
-    CONTENT_NEW: (idws, ctstype) => `/workspace/${idws}/apps/contents/${ctstype}/new`,
19
-    CONTENT_EDIT: (idws, idcts) => `/workspace/${idws}/apps/contents/${idcts}/edit`,
20
-    CONTENT_TITLE_EDIT: (idws, idcts) => `/workspace/${idws}/apps/contents/${idcts}/title/edit`,
21
-    ADMIN: idws => `/workspace/${idws}/admin`
15
+    CALENDAR: (idws = ':idws') => `/workspace/${idws}/apps/calendar`,
16
+    CONTENT_LIST: (idws = ':idws') => `/workspace/${idws}/apps/contents`,
17
+    CONTENT: (idws = ':idws', idcts = ':idcts') => `/workspace/${idws}/apps/contents/${idcts}`,
18
+    CONTENT_NEW: (idws = ':idws', ctstype = ':ctstype') => `/workspace/${idws}/apps/contents/${ctstype}/new`,
19
+    CONTENT_EDIT: (idws = ':idws', idcts = ':idcts') => `/workspace/${idws}/apps/contents/${idcts}/edit`,
20
+    CONTENT_TITLE_EDIT: (idws = ':idws', idcts = ':idcts') => `/workspace/${idws}/apps/contents/${idcts}/title/edit`,
21
+    ADMIN: (idws = ':idws') => `/workspace/${idws}/admin`
22 22
   },
23 23
   LOGIN: '/login',
24 24
   ACCOUNT: '/account'