Is History API broken on iOS? (Location bar doesn't update on pushState)

后端 未结 5 980
你的背包
你的背包 2020-12-08 04:29

Filing this under the either the I Can\'t Believe No One Noticed This Before or the I Must Be Missing Something categories:

It appears that if you do a simple

5条回答
  •  北海茫月
    2020-12-08 05:14

    I found a hack that kinda works. It turns out that if you change the hash right after history.pushState the location bar gets updated. Like:

            window.history.pushState(data, title, 'a/new/url');
            window.location.hash = 'new';
    

    changes the location bar to http://example.com/a/new/url#new. Which introduces another problem because the hash becomes it's own history entry. So you'll need to listen to onHashChange anyway.

    It's a bit complicated, but there are some people who really, really hate hashbang urls and are very vocal about it. So it's worth it.

提交回复
热议问题