@@ -29,6 +29,7 @@ export default class Header extends React.Component {
29
29
}
30
30
31
31
state = {
32
+ currentPath : '/' ,
32
33
showMenus : false ,
33
34
isDarkBg : false ,
34
35
}
@@ -39,6 +40,8 @@ export default class Header extends React.Component {
39
40
if ( maxTop > 0 ) {
40
41
window . onscroll = this . handleScroll
41
42
}
43
+
44
+ this . setState ( { currentPath : location . pathname } )
42
45
}
43
46
44
47
componentWillUnmount ( ) {
@@ -64,6 +67,7 @@ export default class Header extends React.Component {
64
67
}
65
68
66
69
renderMenus ( ) {
70
+ const { currentPath } = this . state
67
71
return (
68
72
< div className = { styles . meuns } >
69
73
< img
@@ -79,7 +83,7 @@ export default class Header extends React.Component {
79
83
key = { item . name }
80
84
href = { item . link }
81
85
className = { classnames ( {
82
- [ styles . active ] : location . pathname === item . active ,
86
+ [ styles . active ] : currentPath === item . active ,
83
87
} ) }
84
88
>
85
89
{ item . name }
@@ -111,7 +115,7 @@ export default class Header extends React.Component {
111
115
112
116
render ( ) {
113
117
const { isBlankBg, hasBg, hasLightBg } = this . props
114
- const { showMenus } = this . state
118
+ const { showMenus, currentPath } = this . state
115
119
const isDarkBg = ! isBlankBg && ( this . state . isDarkBg || hasBg )
116
120
const logoSrc = isBlankBg
117
121
? '/images/op-logo.svg'
@@ -140,7 +144,7 @@ export default class Header extends React.Component {
140
144
key = { item . name }
141
145
href = { item . link }
142
146
className = { classnames ( {
143
- [ styles . active ] : location . pathname === item . active ,
147
+ [ styles . active ] : currentPath === item . active ,
144
148
} ) }
145
149
>
146
150
{ item . name }
0 commit comments