Reactjs 基于布线变换,仅为某些组件设置动画
我有一个React web应用程序,它带有导航等选项卡,每个选项卡都有一个单独的路径。通过某条路线,我可以访问某个选项卡,反之亦然,单击某个选项卡可以到达该路线 问题是,我想从标签页到过渡页进行布线,并仅对某些组件设置动画,而不是对整个视图设置动画-仅对根据布线实际发生变化的部分设置动画Reactjs 基于布线变换,仅为某些组件设置动画,reactjs,react-router,Reactjs,React Router,我有一个React web应用程序,它带有导航等选项卡,每个选项卡都有一个单独的路径。通过某条路线,我可以访问某个选项卡,反之亦然,单击某个选项卡可以到达该路线 问题是,我想从标签页到过渡页进行布线,并仅对某些组件设置动画,而不是对整个视图设置动画-仅对根据布线实际发生变化的部分设置动画 根据路线的不同,可以仅为某些组件设置动画?您的路线应该有一个公共父级,该父级将使用react css transition group设置过渡动画: <Route path="/" component={
根据路线的不同,可以仅为某些组件设置动画?您的路线应该有一个公共父级,该父级将使用react css transition group设置过渡动画:
<Route path="/" component={App}> // The parent
<IndexRoute component={HomePage}/>
<Route path="page1" component={Page1}/>
<Route path="page1" component={Page2}/>
<Route path="page1" component={Page3}/>
<Route path="page1" component={Page4}/>
</Route>
//父对象
在routes容器中,决定路径是否应设置动画,并启用/禁用TransitionOne和transitionLeave:
const App = ({ children, location }) => {
const pathsToAnimate = ['/page1', '/page3']; // a list of routes that should animate
const shouldAnimate = pathsToAnimate.includes(location.pathname); // check if the current route is among the pathsToAnimate
return (
<div>
<ReactCSSTransitionGroup
component="div"
transitionName="example"
transitionEnter={ shouldAnimate } // animate if shouldAnimate is true
transitionLeave={ shouldAnimate } // animate if shouldAnimate is true
transitionEnterTimeout={500}
transitionLeaveTimeout={500}
>
{React.cloneElement(children, {
key: location.pathname
})}
</ReactCSSTransitionGroup>
</div>
);
};
const-App=({children,location})=>{
const pathsToAnimate=['/page1','/page3'];//应设置动画的路由列表
const shouldAnimate=pathsToAnimate.includes(location.pathname);//检查当前路由是否在pathsToAnimate中
返回(
{React.cloneElement(儿童、{
关键字:location.pathname
})}
);
};
您的路由应该有一个公共父级,该父级将使用react css transition group设置过渡动画:
<Route path="/" component={App}> // The parent
<IndexRoute component={HomePage}/>
<Route path="page1" component={Page1}/>
<Route path="page1" component={Page2}/>
<Route path="page1" component={Page3}/>
<Route path="page1" component={Page4}/>
</Route>
//父对象
在routes容器中,决定路径是否应设置动画,并启用/禁用TransitionOne和transitionLeave:
const App = ({ children, location }) => {
const pathsToAnimate = ['/page1', '/page3']; // a list of routes that should animate
const shouldAnimate = pathsToAnimate.includes(location.pathname); // check if the current route is among the pathsToAnimate
return (
<div>
<ReactCSSTransitionGroup
component="div"
transitionName="example"
transitionEnter={ shouldAnimate } // animate if shouldAnimate is true
transitionLeave={ shouldAnimate } // animate if shouldAnimate is true
transitionEnterTimeout={500}
transitionLeaveTimeout={500}
>
{React.cloneElement(children, {
key: location.pathname
})}
</ReactCSSTransitionGroup>
</div>
);
};
const-App=({children,location})=>{
const pathsToAnimate=['/page1','/page3'];//应设置动画的路由列表
const shouldAnimate=pathsToAnimate.includes(location.pathname);//检查当前路由是否在pathsToAnimate中
返回(
{React.cloneElement(儿童、{
关键字:location.pathname
})}
);
};