import React, {Component} from 'react' import {Row, Col, Icon} from 'antd' import {Switch, Route, NavLink, withRouter} from 'react-router-dom' import classnames from 'classnames' import Home from './pages/home' import Cart from './pages/cart' import My from './pages/my' import './app.css' class App extends Component { constructor(props) { super(props) this.state = { selectedTab: 'home', tabHidden: false, page: 'detail' } } componentWillMount() { 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, state = location.state // 有 state 的话,就隐藏 tabbar if (location && state) { this.setState({ tabHidden: true }) } // 根据非首次的 pathname 显示 icon 选中 if (location && pathname) { this.setState({ selectedTab: pathname.substr(1) === '' ? 'home' : pathname.substr(1) }) } } chooseClassNames = (tabbar) => ( classnames( {'tabbar-content': true}, {'tabbar-inactive': this.state.selectedTab !== tabbar}, {'tabbar-active': this.state.selectedTab === tabbar} ) ) render() { let {selectedTab, tabHidden} = this.state return (