Ajax with history.pushState and popstate - what do I do when popstate state property is null?

前端 未结 6 929
遥遥无期
遥遥无期 2021-02-07 01:18

I\'m trying out the HTML5 history API with ajax loading of content.

I\'ve got a bunch of test pages connected by relative links. I have this JS, which handles clicks on

6条回答
  •  隐瞒了意图╮
    2021-02-07 02:08

    I actually found myself with a similar need today and found the code you provided to be very useful. I came to the same problem you did, and I believe all that you're missing is pushing your index file or home page to the history in the same manner that you are all subsequent pages.

    Here is an example of what I did to resolve this (not sure if it's the RIGHT answer, but it's simple and it works!):

    var home = 'index.html';
    history.pushState({page:home}, null, home);
    

    Hope this helps!

提交回复
热议问题