NavigationHistoryEntry:getState() 方法
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
NavigationHistoryEntry
接口的 getState()
方法返回由开发人员提供且与当前历史记录条目相关联的状态的克隆。
语法
js
getState()
参数
无。
返回值
表示状态的值。这可以是任何可结构化克隆的数据类型。
如果未定义状态或当前文档未完全激活,则返回 undefined
。
异常
无。
示例
js
async function handleReload() {
// 通过 reload() 更新现有状态
await navigation.reload({
state: { ...navigation.currentEntry.getState(), newState: 3 },
});
// 将当前状态打印到控制台
const current = navigation.currentEntry;
console.log(current.getState());
}
规范
Specification |
---|
HTML # dom-navigationhistoryentry-getstate-dev |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getState |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参见
- 现代客户端路由:导航 API
- 导航 API 说明
- Domenic Denicola 的导航 API 在线演示
- 允许更新状态的方法——
Navigation.navigate()
、Navigation.reload()
和Navigation.updateCurrentEntry()