History.js onpopstate? [英] History.js onpopstate?

查看:89
本文介绍了History.js onpopstate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习使用History API后尝试实现History.js。但是我的popstate不再工作了。

I am trying to implement History.js after learning to use the History API. However my popstate isn't working anymore.

History.js中使用什么作为 onpopstate ?在历史API中,您使用 onpopstate event.state

What is used in the History.js as the onpopstate? In the history API you use onpopstate with event.state.

我需要知道的是History.js中使用的内容。它是 window.onstatechange 它会返回什么?

What I need to know is what is used in History.js. Is it window.onstatechange and what does it return?

推荐答案

你不能告诉它是推或弹。这是它的设计。
你不应该在推送活动之前做任何事情。相反,您应该将所有必需的数据传递给第一个参数。

You can't tell it's from push or pop. This is by its design. You should not do anything before push event. Instead, you should pass all your required data to the first parameter.

History.pushState(data,title,url)

然后从onstatechange检索数据并执行一些操作。

Then retrieve data from onstatechange and do some actions.

检查: https://github.com/browserstate/history.js/issues/ 47

这篇关于History.js onpopstate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆