LK

Results 22 comments of LK

@songdengwei 之前没有考虑到前进按钮,其实前进按钮也会触发 `popstate` 事件。如果是使用了 HTML5 的 history api 的单页应用,可以在 `pushState` 的时候给要入栈的状态对象加上一个字段来区分历史栈中每个状态的先后顺序,比如 `pushState({s: 'a.html', index: 0}, '', 'a.html')` 和 `pushState({s: 'b.html', index: 1}, '', 'b.html')`,这样当点击浏览器前进后退按钮的时候我们可以通过比较 `e.state.index` 和当前 `history.state.index` 的值来判断具体是入栈还是出栈,不过这只是一个初始的想法,并没有实践过。 如果是多页面应用的话还没有想到什么方法来区分前进后退按钮。

@TheSaltwaterRoom 请问你是直接在控制台输入的类似 `window.onpopstate` 这样的监听代码吗?`popstate` 事件被触发是在**激活状态**的历史条目发生改变的时候,也就是说在监听之前应该先用 `history.pushState` 方法往历史栈中推一条数据,这个时候点击回退按钮才会触发 `popstate` 事件。

@TheSaltwaterRoom 不怎么用 qq... 这里有代码高亮很方便,你可以直接在这里贴出比较完整一点的代码哦

@zhaomenglu 如果是在你这种情况下测试的话,上面的代码需要在 `initialize` 方法里加一条 `history.pushState(1, '', '')`,主动推一条记录到历史栈中。不过有一点需要注意,对于新版的 Chrome 浏览器,跳转到 B 页面之后,用户需要在 B 页面里做一些操作(比如点击元素、输入等等),才能在点击回退按钮的时候触发 `popstate` 事件。

> Experimental support for ESM is in `dd-trace@>=1.3.0`. Simply add the loader hook hook using the following CLI argument to Node.js. > > `--experimental-loader dd-trace/loader-hook.mjs` > > Please contact us...

Here is another workaround mentioned [here](https://stackoverflow.com/questions/51048880/is-there-a-programmatic-way-to-change-user-agent-in-cypress-io), may be useful in some case: ```javascript before(() => { cy.visit(url, { onBeforeLoad: win => { Object.defineProperty(win.navigator, 'userAgent', { value: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',...

> > Here is another workaround mentioned [here](https://stackoverflow.com/questions/51048880/is-there-a-programmatic-way-to-change-user-agent-in-cypress-io), may be useful in some case: > > ```js > > before(() => { > > cy.visit(url, { > > onBeforeLoad: win...

感谢喜欢😁 你说的这个问题应该是网络原因,我测试在网络环境较差的情况下确实可能会出现没有 suggestion 的情况

你好,请问React中的component 里的key具体起到什么作用呢?如果没有的话好像也不会让程序产生异常,只会有个警告,那代表key是不是可有可无呢?