AngularJS, using routes without refreshes on back button

前端 未结 3 1930
名媛妹妹
名媛妹妹 2021-02-14 09:17

I\'m using angularJS to build a simple single page application using AJAX, but I\'m running into a problem when users use the native back button.

an         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-14 09:54

    Yep, the Back button and the the Refresh button are a real pain. You have two choices:

    1. You keep things simple and just allow your state to be fetched for each location change. This treats a user triggered back button click or a refresh as any normal location change. Data re-fetching can be mitigated by http caching.

    2. You maintain your own state on the client and restore it when required, possibly using SessionStorage to keep things clean.

    I chose the latter option and it all works just fine for me. See these self answered questions for detailed code examples.

    • How do I get the Back Button to work with an AngularJS ui-router state machine?
    • How do I handle page refreshing with an AngularJS Single Page Application

提交回复
热议问题