7
7
import React from 'react'
8
8
import T from 'prop-types'
9
9
import R from 'ramda'
10
+ import { withRouter } from 'next/router'
10
11
11
12
import { ROUTE , C11N } from '@/constant'
12
- import { buildLog } from '@/utils'
13
+ import { buildLog , getRoutePathList } from '@/utils'
13
14
14
15
import DigestView from './DigestView'
15
16
import BriefView from './BriefView'
16
17
17
18
/* eslint-disable-next-line */
18
19
const log = buildLog ( 'c:Navigator:index' )
19
20
20
- const Navigator = ( { curCommunity, layout, curRoute } ) => {
21
- const { mainPath, subPath} = curRoute
21
+ const Navigator = ( { curCommunity, layout, router } ) => {
22
+ const [ mainPath , subPath ] = getRoutePathList ( router . asPath )
22
23
23
24
if (
24
25
R . contains ( mainPath , [ ROUTE . USER , ROUTE . COMMUNITIES ] ) ||
25
26
R . contains ( subPath , [ ROUTE . POST , ROUTE . JOB , ROUTE . VIDEO , ROUTE . REPO ] )
26
27
) {
27
- return < DigestView curRoute = { curRoute } />
28
+ return < DigestView />
28
29
}
29
30
30
31
return (
31
32
< React . Fragment >
32
33
{ layout === C11N . DIGEST ?(
33
- < DigestView curRoute = { curRoute } />
34
+ < DigestView />
34
35
) :(
35
- < BriefView community = { curCommunity } curRoute = { curRoute } />
36
+ < BriefView community = { curCommunity } />
36
37
) }
37
38
</ React . Fragment >
38
39
)
@@ -41,15 +42,11 @@ const Navigator = ({ curCommunity, layout, curRoute }) => {
41
42
Navigator . propTypes = {
42
43
curCommunity :T . object ,
43
44
layout :T . oneOf ( [ C11N . DIGEST , C11N . BRIEF ] ) ,
44
- curRoute :T . shape ( {
45
- mainPath :T . string ,
46
- subPath :T . string ,
47
- } ) . isRequired ,
48
45
}
49
46
50
47
Navigator . defaultProps = {
51
48
curCommunity :{ } ,
52
49
layout :C11N . DIGEST ,
53
50
}
54
51
55
- export default React . memo ( Navigator )
52
+ export default React . memo ( withRouter ( Navigator ) )