|
@@ -20,6 +20,19 @@ class App extends Component {
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
componentWillMount() {
|
|
|
let {location} = this.props,
|
|
let {location} = this.props,
|
|
|
|
|
+ pathname = location.pathname
|
|
|
|
|
+
|
|
|
|
|
+ // 根据首次的 pathname 显示 icon 选中
|
|
|
|
|
+ console.log(pathname)
|
|
|
|
|
+ if (location && pathname) {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ selectedTab: pathname.substr(1) === '' ? 'home' : pathname.substr(1)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ componentWillReceiveProps(next) {
|
|
|
|
|
+ let {location} = next,
|
|
|
pathname = location.pathname,
|
|
pathname = location.pathname,
|
|
|
state = location.state
|
|
state = location.state
|
|
|
|
|
|
|
@@ -30,10 +43,10 @@ class App extends Component {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 根据 pathname 显示 icon 选中
|
|
|
|
|
|
|
+ // 根据非首次的 pathname 显示 icon 选中
|
|
|
if (location && pathname) {
|
|
if (location && pathname) {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
- selectedTab: pathname.substr(1) === ''? 'home' : pathname.substr(1)
|
|
|
|
|
|
|
+ selectedTab: pathname.substr(1) === '' ? 'home' : pathname.substr(1)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|