react页面过渡动画简单实现

1. 在配置路由的外层父元素添加className

class App extends Component {
  render() {
    return (
      <div className='animate-route'>
        <Router>
          <Globalstyle />

          <Route exact path='/home' component={Home} />
          <Route exact path='/login' component={Login} />
        </Router>
      </div>
    );
  }
}

export default App;

 2. index.less文件添加如下代码:

.animate-route {
    animation-duration: 1s;
    animation-fill-mode: both;
    animation-name: fadeRoute;
}

@keyframes fadeRoute {
    from {
        opacity: 0;
    }
    to {
      opacity: 1;
    }
}

 

posted @ 2019-08-21 17:36  Courage.Kiven  阅读(1744)  评论(0编辑  收藏  举报