我想为反应路由器创建一个过渡动画,但它似乎不起作用(没有过渡)。
正如您在下面看到的,我所做的只是创建一个组件 FadeRoute,它使用 ReactCSSTransitionGroup 创建动画,然后我在 react-router-dom 的 switch 组件中使用它
这是我的反应代码
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import { browserHistory } from "react-router";
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
function FadeRoute({ component: Component, ...rest }) {
return (
<Route {...rest} children={({ location, match }) => (
<ReactCSSTransitionGroup
transitionName="fade"
transitionEnterTimeout={300}
transitionLeaveTimeout={300}>
<Component />
</ReactCSSTransitionGroup>
)
} />
);
}
class App extends React.Component {
render() {
return (
<Router history={browserHistory}>
<Switch>
<FadeRoute exact path="/" component={Home} />
<FadeRoute exact path="/NextComponent" component={NextComponent} />
<FadeRoute component={NoMatch} />
</Switch>
</Router>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
这里是css代码
.fade-enter {
opacity: 0.01;
}
.fade-enter.fade-enter-active {
opacity: 1;
transition: opacity 500ms ease-in;
}
.fade-leave {
opacity: 1;
}
.fade-leave.fade-leave-active {
opacity: 0.01;
transition: opacity 300ms ease-in;
}
你能帮我找到铅在哪里吗?先感谢您