[英]How does google maps change its URL without reloading and without using the history API?
So if you do anything on google maps (maps.google.com) such as search or click a place etc the URL changes and the page is clearly not reloading (can tell from the inspect element/console). 因此,如果您在Google地图(maps.google.com)上执行任何操作(例如搜索或单击某个地点等),则URL会更改,并且页面显然不会重新加载(可以从inspect元素/控制台中得知)。 I thought they might be using the HTML5 history API but that doesn't seem to be the case (window.history.currentState always returns undefined regardless of how many times the URL has changed).
我以为他们可能正在使用HTML5历史记录API,但事实并非如此(无论URL更改了多少次,window.history.currentState始终返回undefined)。
So how does google do this? 那么,谷歌如何做到这一点?
Related questions from past (like 2010) also mentioned the hashtag method which they clearly don't use anymore (no hashtags anywhere in any of the URLs) 过去(例如2010年)的相关问题也提到了他们显然不再使用的hashtag方法(任何URL的任何地方都没有hashtag)
So I was wrong,they actually do seem to use the history API. 所以我错了,他们实际上确实使用了历史API。 Not sure why currentState always returned undefined but if I call window.history.state you can see the index changing and if you call back() it does what you'd expect.
不知道为什么currentState总是返回undefined,但是如果我调用window.history.state,则可以看到索引发生了变化,如果您调用back(),它可以达到预期的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.