react-transition-group - 从转换中排除嵌套路由
问题描述
我有一个简单的画廊应用程序,它有 2 条顶级路线。其中之一 ('/album') 有一个名为 '/image' 的嵌套路由,它接受 imageId 作为参数('/album' 接受 :albumId)。在单图像视图中切换图像时,我不想应用过渡。具体来说,如果可能的话,我不希望它的父级('/album')只为嵌套的'/image'设置动画(因为它的行为方式是整个页面淡入淡出,即使是列出缩略图的组件,它看起来未完成)。到目前为止,我找不到任何解决方案来为孩子制作动画和跳过父母,只有相反的方式(甚至它有点骇人听闻)。我尝试在顶层移出'/album/image/:imageId',但这种方式进出'/image'从/到其他路线没有过渡,以不一致的感觉/行为离开应用程序。这就是扁平化路由的外观
<Switch>
<Route path="/image/:albumId/:imageId">
<Photo></Photo>
</Route>
<Route path="/">
<TransitionGroup>
<CSSTransition key={location.key} classNames="fade" timeout={TRANSITION_LENGTH}>
<Switch location={location}>
<Route path="/album-list">
<AlbumList></AlbumList>
</Route>
<Route path="/album/:albumId">
<Album></Album>
</Route>
<Route path="/">
<Redirect to="/album-list"></Redirect>
</Route>
</Switch>
</CSSTransition>
</TransitionGroup>
</Route>
</Switch>
这就是嵌套的过去的样子:
<Link to="/">Back to Albums</Link>
<h1>Photos in <Link to={`${url}`}>{album.name}</Link></h1>
<Switch>
<Route path={`${path}/image/:imageId`}>
<Photo></Photo>
<div className="List">
{album.photos.map((photo, index) => {
return <div className="Photo" key={index}>
<Link to={`${url}/image/${photo.id}`}>
<img src={photo.thumbnailUrl}/>
</Link>
</div>
})}
</div>
</Route>
<Route>
<div className="Grid">
{album.photos.map((photo, index) => {
return <div className="Photo" key={index}>
<Link to={`${url}/image/${photo.id}`}>
<img src={photo.thumbnailUrl}/>
</Link>
</div>
})}
</div>
</Route>
</Switch>
解决方案
推荐阅读
- openshift - OpenShift 日志记录:如何将堆栈跟踪的 Kibana 组行合并到一个记录中?
- excel - 使用 Excel VBA 自动获取网站图像 URL
- ruby-on-rails - 如何读取哈希数组作为 input.txt 文件以在 ruby 中排序
- java - 批量插入和提取的 JPA/Hibernate 性能改进
- node.js - 如何在后端重新启动 expressjs 应用程序并同时重新加载浏览器选项卡?
- pandas - 如何将前一行的值分配给当前行?
- python - 如何将 Kivy 应用程序连接到数据库
- redhawksdr - 不与域管理器关联的分布式 Redhawk 设备管理器
- apache-kafka - 如果 Apache Kafka 收到 2 MB 消息会发生什么?由于默认大小仅为 1 MB
- python - 将带有int和字典的字符串转换为列表