URL 与 History 实验台

输入完整 URL,观察 JavaScript 如何把地址拆成几段;再用一组按钮模拟 history 栈的移动。

window.location / history

URL 拆解

基于 URL 对象实时解析

protocol + host + path + search + hash
protocol
host
path
hash
origin
hostname
port
searchParams

模拟历史栈

只模拟,不改真实浏览器历史

当前模拟 URL

    这里的按钮不会调用浏览器的真实 history API,只是在页面里演示 push、replace、back、forward 对栈和当前位置的影响。