Browser History Management

不打扰是莪最后的温柔 提交于 2019-12-06 10:02:14

window.history has a length attribute that will show you how many entries are in the history for the current tab. It is unfortunately not filterable (so there is no way to say window.history.localURLs.length).

If you are doing this almost entirely on the client side (i. e. partial updates, very few full-page loads, using hashes or the history.(push|pop)State API) then you may want to look into incorporating a client-side routing framework into your application to avoid re-inventing the wheel.

Before your user can access #LOGIN dialog, your entry point class is executed. In this class you can remember the last known page. In Login activity/presenter you can add a browser history event handler, which checks if the last known place is null or not. If null, send a user to the #HOME page.

You don't need to ask the browser which places in your app a user has visited. You can remember the entire history of each session, if you want to: i.e. [#HOME, #LOGIN, #FEATURES, #HOME].

How about you have a Queue<String> historyQueue;

When the page loads for the first time, i.e. onModuleLoad() you initalize the Queue. When you capture a history event, check if its a back or a new history token. If its a back, you pop it out from the queue, if its a new one you add it to the queue. This way, the cancel button is just a token = historyQueue.pop() and check if the token is null. If it is, then like you said back = cancel, so just do the appropriate thing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!