Set URL parameters without causing page refresh

后端 未结 3 1114
攒了一身酷
攒了一身酷 2021-02-20 16:06

How can you set URL parameters using History.pushState() to avoid browser refreshes? If there is a not a simple JS solution, is there already a popular library or b

3条回答
  •  我在风中等你
    2021-02-20 16:19

    Answering to the question in your comment, you'd be able to read those properties from history.state, a property that holds the value of the stat for the current URL. Whenever you go back and forward you'll receive a popstate event and you will be able tor read the state you pushed, which is far easier than dealing with urls.

    Of course, when you go back or forward to a new entry in the history list pushed with pushState() or replaceState() the page does not reload.

    You can read more about the History object in the MDN.

提交回复
热议问题