反应路由器,好奇它是如何做到 url 没有散列的导航
react router, curious as to how it does url navigation without hashes
使用 create react app 你可以连接一个路由器并且它导航 没有 #,就像 index/page1 一样,我认为浏览器会自动将它发送到作为客户端的服务器仅捕获# 更改,这是一个纯粹出于好奇的问题,所以反应如何进行正确的 url 导航我正在使用 create react app with yarn 我猜它使用某种类型的节点网络服务器。我们什么时候举办这个怎么样?
来自the History API article on Mozilla Developer Network:
Suppose http://mozilla.org/foo.html executes the following JavaScript:
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
This will cause the URL bar to display http://mozilla.org/bar.html,
but won't cause the browser to load bar.html or even check that
bar.html exists.
(根据Mozilla Contributors, licensed under CC-BY-SA 2.5)
因此,使用 history.pushState
您可以更改 URL 栏中的位置,而无需实际执行导航。 (但是,我相信如果用户重新加载页面,浏览器将向服务器请求新的 URL,因此服务器仍应 return 新 URL 的适当页面。)
使用 create react app 你可以连接一个路由器并且它导航 没有 #,就像 index/page1 一样,我认为浏览器会自动将它发送到作为客户端的服务器仅捕获# 更改,这是一个纯粹出于好奇的问题,所以反应如何进行正确的 url 导航我正在使用 create react app with yarn 我猜它使用某种类型的节点网络服务器。我们什么时候举办这个怎么样?
来自the History API article on Mozilla Developer Network:
Suppose http://mozilla.org/foo.html executes the following JavaScript:
var stateObj = { foo: "bar" }; history.pushState(stateObj, "page 2", "bar.html");
This will cause the URL bar to display http://mozilla.org/bar.html, but won't cause the browser to load bar.html or even check that bar.html exists.
(根据Mozilla Contributors, licensed under CC-BY-SA 2.5)
因此,使用 history.pushState
您可以更改 URL 栏中的位置,而无需实际执行导航。 (但是,我相信如果用户重新加载页面,浏览器将向服务器请求新的 URL,因此服务器仍应 return 新 URL 的适当页面。)