有什么方法可以在不刷新的情况下更改浏览器中的 url 吗?
我希望更改 url localhost/users?page=2
的查询参数,并且对如何在不刷新的情况下实现这一点很感兴趣。
答案 0 :(得分:-1)
阅读react-router-dom
here
答案 1 :(得分:-1)
浏览器 history 有两种不同的更新 URL 的方法,一种会导致重新加载,另一种不会。您要使用的是 history.replaceState()
根据 MDN 文档,
<块引用>然后假设 https://www.mozilla.org/bar.html 执行以下 JavaScript:
history.replaceState(stateObj, '', 'bar2.html');
这会导致 URL 栏显示 https://www.mozilla.org/bar2.html,但不会导致浏览器加载 bar2.html 甚至检查 bar2.html 是否存在。