聊聊React的路由React-Router、react-router-dom

react

关于二者的区别

参见:https://github.com/mrdulin/blog/issues/42  

直接使用react-router-dom好了,react-router-dom封装了react-router,也依赖react-router-dom

BrowserRouter vs HashRouter

import { BrowserRouter as Router } from 'react-router-dom';

// import { HashRouter as Router } from 'react-router-dom';

建议使用BrowserRouter, url类似http://127.0.0.1:8088/api/v1/test,HashRouter慢慢会被废弃,url类似http://127.0.0.1:8088/#/api/v1/test,会自动添加/#

详情参考:https://www.jianshu.com/p/e3adc9b5f75c

为什么我的url输入每次都会自动添加一个#?参见上面

react-router文档

英文:

https://reacttraining.com/react-router/web/guides/quick-start

中文:

https://react-guide.github.io/react-router-cn/docs/Introduction.html

以上是 聊聊React的路由React-Router、react-router-dom 的全部内容, 来源链接: utcz.com/z/381746.html

回到顶部