react-router vs react-router-dom,什么时候使用一个? [英] react-router vs react-router-dom, when to use one or the other?

查看:41
本文介绍了react-router vs react-router-dom,什么时候使用一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者都有 Route、Link 等.何时使用其中一个?我真的很困惑在哪里使用每个.服务器端?客户端?

Both have Route, Link, etc. When to use one or the other? I'm really confused on where to use each one. Server side? Client side?

https://reacttraining.com/react-router/

在某些示例中,您需要传递历史记录,而在其他示例中则不需要.怎么办?

In some examples you need to pass the history, in others not. What to do?

<Router history={browserHistory}>

对比

<Router>

关于何时使用一种或另一种确实令人困惑,任何帮助表示赞赏.

It's really confusing on when to use one or the other, any help appreciated.

推荐答案

react-router 包含 react-router-domreact 之间的所有公共组件-路由器本地.什么时候应该使用一个?如果您在网络上,那么 react-router-dom 应该拥有您需要的一切,因为它还导出您需要的通用组件.如果您使用的是 React Native,出于同样的原因,react-router-native 应该拥有您需要的一切.因此,您可能永远不必直接从 react-router 导入任何内容.至于当你使用

react-router contains all the common components between react-router-dom and react-router-native. When should you use one over the other? If you're on the web then react-router-dom should have everything you need as it also exports the common components you'll need. If you're using React Native, react-router-native should have everything you need for the same reason. So you'll probably never have to import anything directly from react-router. As far as when you use

<Router history={browserHistory}>

对比

<Router>

在 RRv4 中,您不需要向下传递 browserHistory,这仅适用于以前版本的路由器.

In RRv4 you won't need to pass down browserHistory, that was just for previous versions of the router.

如果你仍然一头雾水,你可以查看每个包的详细信息这里

If you're still confused, you can check out the details on each package here

这篇关于react-router vs react-router-dom,什么时候使用一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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