深入理解 HTML History 对象 深入理解 HTML History 对象 环境搭建 History 对象介绍 pushState & replaceState History stack 参考 深入理解 HTML History 对象 环境搭建 安装包 mkdir example-window-history cd example-window-history yarn init -y yarn add http-server 添加如下内容到 package.json 文件中 "scripts": { "start": "http-server" }, 创建 public/foo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> Foo <button onclick="handleClick()">history pushState</button> <script> function handleClick() { let stateObj = { foo: 'bar' }; window.history.pushState(stateObj, 'page 2', 'bar.html'); } console.log(`foo.history.state = ${ JSON.stringify(history.state)}`); </script> </body> </html> 创建 public/bar.html