如何在react中实现路由的切换动画
1 yarn add react-animated-router --save 或者 npm i yarn add react-animated-router --save 插件
2 yarn add react-transition-grop --save 第一个库依赖这个库
具体用法
import React, { Component } from 'react'
import { HashRouter as Router, Switch, Route } from 'react-router-dom'
import AnimatedRouter from 'react-animated-router';
import 'react-animated-router/animate.css';
export default class App extends Component {
constructor(props){
super(props)
}
render() {
return (
<Router>
<AnimatedRouter> {}
<Route exact path='/' component={ Home }></Route>
</AnimatedRouter>
<Switch> {}
<Route path='/index' component={ Index }></Route>
<Route path='/test' component={ Test }></Route>
</Switch>
</Router>
)
}
}
附带
import { CSSTransition } from "react-transition-group";
详情看官方