admin管理员组文章数量:1410682
A similar question here has been noted!
I've got an SPA based exclusively on the DHTMLX toolkit (fabulous stuff incidentally). One serious UX problem is with back button handling: there is none.
Their forum remended 'any js routing library to handle state of the app in the url hash and restore it back'.
I am confused by this as the SPA has only the simplest HTML, is exclusively Javascript and does most municating via WebSockets ... does this mean I have to store state on each button click/keypress?
So, ...
- Does the panel have any remendations on best practices?
- Is there an existing library that will do this?
- If said library is light on examples, can anyone provide a basic how-to?
Many thanks
A similar question here has been noted!
I've got an SPA based exclusively on the DHTMLX toolkit (fabulous stuff incidentally). One serious UX problem is with back button handling: there is none.
Their forum remended 'any js routing library to handle state of the app in the url hash and restore it back'.
I am confused by this as the SPA has only the simplest HTML, is exclusively Javascript and does most municating via WebSockets ... does this mean I have to store state on each button click/keypress?
So, ...
- Does the panel have any remendations on best practices?
- Is there an existing library that will do this?
- If said library is light on examples, can anyone provide a basic how-to?
Many thanks
Share Improve this question edited May 23, 2017 at 12:00 CommunityBot 11 silver badge asked Dec 20, 2014 at 13:12 J EvansJ Evans 1,1323 gold badges17 silver badges38 bronze badges1 Answer
Reset to default 3Dhtmlx is a great framework for building SPAs. Like all SPAs, the back button will simply take the user right out of app. Also the user cannot bookmark anything.
So what you want to do is use javascript's pushState()
which will allow you to control the url.
For example, suppose you show a search screen to go to a record. The user enters the search criteria and presses search. You bring in the results via ajax and update a grid. Then the user selects the row and you go to a detail page (typical search functionality here).
At this point, you would want to use pushState()
to change the url to something like:
http:/me./search/23432
This will allow the user to bookmark the page. Then when the user leaves the detail page, use pushState()
and set the url to http:/me./search
So you have plete control over the url.
The next thing you need to learn is popState()
. This function is called when the url changes. So suppose the user pushes the bookmark to go to "23432". popState()
will be called and you'll react accordingly.
That's basically it in a nutshell: pushState()
and popState()
.
Some older browsers do not react to pushState/popState. There are libraries floating around to handle older browsers using url hashing. I am not too familiar with them as I am only supporting html5 browsers.
本文标签: javascriptBack button handling in Single Page AppsStack Overflow
版权声明:本文标题:javascript - Back button handling in Single Page Apps? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744920349a2632255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论