反应路由器选项卡——保持组件安装 [英] React Router Tabs -- Keep Components Mounted

查看:43
本文介绍了反应路由器选项卡——保持组件安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 React Router 创建了选项卡,每个选项卡都有不同的路由.但是,我想通过安装隐藏的选项卡来保持选项卡转换之间的选项卡状态.我如何实现这一目标?每次路由切换时,React 路由器都会重新安装每个组件.

I have created tabs using React Router, with a different route for each tab. However, I would like to maintain the tab state between tab transitions by keeping the hidden tabs mounted. How do I achieve this? React router remounts each component every time the route switches.

已经有人在这里问过这个问题,但是尚未收到答复

Someone has already asked this question here, but has not received an answer

理想情况下,我会找到一种解决方案,使第一次点击后未显示的标签保持安装

Ideally I would find a solution which keeps the tabs which are not displayed mounted after they are hit for the first time

推荐答案

我还得再多挖掘一点才能确认这确实有效,但是通过阅读 React Router 文档我发现 this 关于 Route 组件.使用 component 属性可以在每次路由更改时重新安装组件.但是使用其他渲染方法,您可能能够实现您想要的.我会使用 render,但 children 也可以吗?

I'd have to do a little more digging to confirm this actually works, but reading through React Router docs I found this about the Route component. Using the component prop makes the component remount every time the route changes. But using the other render methods, you might be able to achieve what you're looking for. I'd go with render, but children might work too?

这篇关于反应路由器选项卡——保持组件安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆