当前位置:网站首页>HashRouter 和 HistoryRouter的区别和原理
HashRouter 和 HistoryRouter的区别和原理
2022-06-09 03:56:00 【m0_49471668】
HashRouter和 HistoryRouter的区别:
1. history和hash都是利用浏览器的两种特性实现前端路由,history是利用浏览历史记录栈的API实现,hash是监听location对象hash值变化事件来实现
2. history的url没有'#'号,hash反之
3. 相同的url,history会触发添加到浏览器历史记录栈中,hash不会触发,history需要后端配合,如果后端不配合刷新新页面会出现404,hash不需要。
HashRouter的原理:通过`window.onhashchange`方法获取新URL中hash值,再做进一步处理 HistoryRouter的原理:通过`history.pushState `使用它做页面跳转不会触发页面刷新,使用`window.onpopstate` 监听浏览器的前进和后退,再做其他处理
加分回答
hash模式下url会带有#,需要url更优雅时,可以使用history模式。 需要兼容低版本的浏览器时,建议使用hash模式。 需要添加任意类型数据到记录时,可以使用history模式。
边栏推荐
- Interface performance test: Web service interface test
- How to calculate the number of parameters in the LSTM layer
- Apple Announces Winner of the 2022 Apple Design Award
- 【5月考试】ORACLE OCP 19C 通过
- Getting started with Maui custom drawing
- JVM内存查看及设置思路
- Analysis of constant pool related problems
- Solve the problem that the MySQL library or table is stuck during deletion and other operations
- 什么是算子下盘?
- Method of accessing LAN by external network and how virtual machines installed by VM access each other in LAN
猜你喜欢

基於FPGA的VGA顯示彩條、字符、圖片

Assembly: common commands for debug

Getting started with Maui custom drawing

Attention OCR Chinese version mas ter code running logic

C language interview tube: talk about the functions of various string functions. I: I don't know. Interviewer: come back for an interview when the young man has learned how to do it.

Interface performance test: Web service interface test

汇编:Debug的常用命令

Ideal使用小技巧

人才缺口50万以上,平均薪资20K?网络安全,测试员的下一个风口~

Domain name resolution (public network)
随机推荐
什么是算子下盘?
How to write test cases for [e-commerce] test coupons in 2022?
The students of Turing class of Peking University won the first place in the global undergraduate competition and solved the EDA "neck sticking" technical problem!
Rich color changes
Calculation method and comparison steps of target detection model map -- compare the map between the original model and the quantitative model
How to calculate the number of parameters in the LSTM layer
Merkle Patricia trie principle
Software engineering final exam questions and answers (detailed and classic)
What is the value of Yuan universe virtual real estate?
Mongodb builds replica set cluster
如何撰写数据中台蓝图方案
Assembly: CPU structure - flag register and related instructions
全国大学生信息安全竞赛(CISCN)-reverse-复现(部分)
Why common read SQL is sent to the master instance in the distributed dble read / write separation scenario
人才缺口50万以上,平均薪资20K?网络安全,测试员的下一个风口~
知识点滴- BC和BCE的区别
HLS 直播协议m3u8详解
Final assignment of Web Design - scenic spot tourism website (including navigation bar, rotation map, exquisite style)
基于OpenCV的人脸检测、训练、识别
PHP deserialization recurrence - no response to the bugku login