我应该使用react-router作为标签组件吗? [英] Should I use react-router for a tabs component?

查看:112
本文介绍了我应该使用react-router作为标签组件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个标签组件,其中一些标签将包含动态内容。我最初开始学习本教程:

I'm looking to build a tabs component, where some of the tabs will contain dynamic content. I originally started to follow this tutorial:

使用React创建标签组件

在阅读react-router后,似乎它也可以解决这个问题。什么是更好的方法和/或它有所作为?

After reading up on react-router, it seem's like it could also solve this problem. What would be the better approach and/or does it make a difference?

推荐答案

是的,这是一个完美的工作对于React Router ,因为它侧重于简化单页应用程序的URL重定向过程。

Yes, this is a perfect job for React Router because it focuses on simplifying the URL redirection process for Single Page Apps.

用于导航的选项卡的用例,绝对属于反应路由器。您可以使用React Router 3或4,但 React Router 4 API即将推出而且文档看起来很棒。

The use case of tabs for navigation, definitely falls under the scope of React Router. You can use React Router 3 or 4 for this, but the React Router 4 API is on the horizon and the documentation is looking great.

您可以在上面的链接中找到有用的示例,其中显示了与标签链接的简便程度。 这是一个示例,讨论如何使用自定义创建标签链接。

You can find a helpful example on the link above that shows how easy it is to link with tabs. And here is an example that discusses how you can create tabs with custom links.

你可能要考虑的其中一个 陷阱 就是存在一些困难如果导航到其他路线,则会恢复滚动位置,然后导航回上一个路线。以下是一个讨论此问题的主题: https://github.com/ReactTraining/反应路由器/问题/ 1686

One of the "gotchas" though that you may want to consider, is that there has been some difficulty restoring the scroll position if you navigate to a different route and then navigate back to the previous route. Here is a thread that discusses this issue further: https://github.com/ReactTraining/react-router/issues/1686.

如果恢复滚动位置对您来说非常重要,那么在这一点上,React Router可能不是最适合标签的。

If restoring scroll position is very important to you, then at this point React Router may not be the best fit for tabs.


更新:

Update:

React router v4已经发布,上面的问题已经解决,现在,文档有如何恢复滚动位置的指南!

React router v4 has been released, the issue above has been resolved, and now the docs have a guide on how to restore scroll position!

这篇关于我应该使用react-router作为标签组件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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