import withRouter from 'umi/withRouter';
import { CSSTransition, SwitchTransition } from 'react-transition-group';
import styles from './style.less';

export default withRouter((props) => {
  const currentURL = props.location.pathname + props.location.search

  return (
    <SwitchTransition>
      <CSSTransition
        key={currentURL}
        addEndListener={(node, done) => node.addEventListener("transitionend", done, false)}
        classNames={{
          enter: styles['page-fade-enter'],
          enterActive: styles['page-fade-enter-active'],
          exit: styles['page-fade-exit'],
          exitActive: styles['page-fade-exit-active']
        }}
      >
        <div>
          {props.children}
        </div>
      </CSSTransition>
    </SwitchTransition>
  );
})
