hashHistory and browserHistory in React-Router

简介:

hashHistory and browserHistory are two kinds of common React-Router Histories implementations.
When I was using React-Router v1.0, I read the doc in github and wrote the code like this

import { Router} from 'react-router'
ReactDOM.render (( 
 <Router>
   ...
), document.body);

I found something in url like #/home/k=ckuvupr. What the hell is this?
I went back to the doc and changed the code with browserHistory. With the doc, I knew the default implementation ishashHistory, which will make a # -- hash in url.

import { browserHistory } from 'react-router'
ReactDOM.render (( 
 <Router history={browserHistory} >
   ...
), document.body);

However, it would not effect in v1.0, it's the way in v2.0. So I didn't see anything changed. And just for a while, I forgot to deal with this, and went to write other codes.

Today when I c&p this chunk of code to my new project, using some new tools. The build tool automatically install react-router v2.0 for me. While the hash tag is gone, and url looks like the real url. But it cause another problem, that is when the url is like the real url, it means that I should set the server side route to /* -> index.html rather than / -> index.html.
Otherwise, it will get a 404 error when the url /home is re-flushed. And the problem will not raise while usinghashHistory, because the url is like /#/home and it is still /, the string after hash tag is not in the route rule. Docs about them.

I havn't find the correct way to set the server side route, because I am using a webpack-dev-server-like tool, I don't know how to change the route.
So I go back to use the ugly hashHistory.

It seems a waste of time, my fault is reading doc but not paid attention to version, but I still hate the doc because the difference between v1.0 and v2.0 is not heightlighted.


目录
相关文章
|
9月前
|
安全 Java 测试技术
告别手动部署噩梦:CI/CD 持续交付全链路实战
本文系统讲解Java项目CI/CD落地实践:厘清CI(持续集成)、CD(持续交付/部署)核心概念与本质区别;详解自动化流水线设计,涵盖代码检查(CheckStyle/SpotBugs/SonarQube)、单元测试、依赖安全扫描(OWASP)、容器化构建(Docker+GitHub Actions)及多环境部署;深入剖析蓝绿、金丝雀等零停机发布策略,并提供可运行的Shell脚本实战;最后总结八大最佳实践与六大高频避坑指南。
1047 1
|
12月前
|
存储 小程序 前端开发
开源版婚恋社交系统:基于PHP开发,集成实时音视频匹配、IM聊天、邀约组局与红娘管理模块的小程序!
系统基于uni-app+PHP全开源架构,支持1V1音视频、IM聊天、兴趣组局、红娘匹配等功能,覆盖都市社交、线上相亲、线下活动等多元场景,助力高效交友与婚恋服务,跨端兼容,灵活二开。
1040 1
|
人工智能 安全 Java
Spring Boot yml 配置敏感信息加密
本文介绍了如何在 Spring Boot 项目中使用 Jasypt 实现配置文件加密,包含添加依赖、配置密钥、生成加密值、在配置中使用加密值及验证步骤,并提供了注意事项,确保敏感信息的安全管理。
1953 1
|
机器学习/深度学习 编解码 算法
《探秘目标检测算法:YOLO与Faster R-CNN的原理及发展之旅》
目标检测是计算机视觉的重要任务,旨在识别图像或视频中的目标及其类别。早期依赖滑动窗口和人工特征(如HOG、SIFT),结合SVM等分类器,但计算量大、精度有限。随着深度学习兴起,R-CNN系列(R-CNN、Fast R-CNN、Faster R-CNN)逐步引入CNN和区域提议网络(RPN),显著提升速度和精度。YOLO系列(v1-v8)将检测视为回归问题,直接预测边界框和类别,以速度快著称。近年,基于Transformer的DETR等模型崭露头角,利用自注意力机制捕捉全局信息。未来,目标检测将在精度、速度和泛化能力上取得更大突破。
1022 16
|
人工智能 编解码 算法
Doubao-1.5-pro:字节跳动最新豆包大模型,性能超越GPT-4o和Claude 3.5 Sonnet
豆包大模型1.5是字节跳动推出的最新大模型,采用大规模稀疏MoE架构,支持多模态输入输出,具备低时延语音对话能力,综合性能优于GPT-4o和Claude 3.5 Sonnet。
3397 2
Doubao-1.5-pro:字节跳动最新豆包大模型,性能超越GPT-4o和Claude 3.5 Sonnet
|
设计模式 算法 定位技术
策略模式(Strategy Pattern)
策略模式(Strategy Pattern)是一种行为型设计模式,允许在运行时选择算法或行为,而不是在编译时确定。通过将具体算法封装成独立的类,并通过统一接口与客户端交互,实现算法的动态替换,避免代码重复和复杂条件语句。适用于支付方式切换、导航路径选择等场景。
|
机器学习/深度学习 数据采集 自然语言处理
图像分类模型评估之用python绘制混淆矩阵confusion_matrix_python confusion_matrix
图像分类模型评估之用python绘制混淆矩阵confusion_matrix_python confusion_matrix
|
存储 算法 测试技术
【STM32项目】基于Stm32c8t6-镭射激光打印机的设计(完整工程资料源码)(二)
【STM32项目】基于Stm32c8t6-镭射激光打印机的设计(完整工程资料源码)(二)
730 0
|
JavaScript UED
如何在Vue3项目中使用防抖节流技巧
在Vue 3项目中使用防抖和节流技巧以优化组件性能,包括使用`lodash`库和自定义实现这两种方法。
1934 0
如何在Vue3项目中使用防抖节流技巧
|
Windows
Windows删除文件时如何取消显示“确认是否删除”的弹窗
本文介绍Windows电脑删除文件时,开启或取消显示确认删除这一提示弹窗的方法~
1920 1
Windows删除文件时如何取消显示“确认是否删除”的弹窗