best practise in SPA: hash vs questionmark url

南笙酒味 提交于 2019-12-11 04:27:42

问题


I have a single page app. and just realized that if I replace my location.hash approach to change state with a query approach I would simplify the app. and get the history (back button) for free. (rather than listening to onhashchange events)

So my urls would move from

http://.../spa.html#state={...}
http://.../spa.html?state={...}

The disadvantage is that moving from '#' to '?' implies that the page gets reloaded (which is fine because the state is retrievable) but, although I can see it, it could take longer and/or flicker.

Are there any best recommendation on this ?


回答1:


That’s kind of the point of an SPA (or at least a major part of it)—to improve the user experience by not having to reload the page. You’re not doing traditional pre-rendered document exchange anyway, which means non-JavaScript-enabled agents are out of the picture already. Thus, with your solution, you’re trading off a major user experience boon for a minor simplification in your code.



来源:https://stackoverflow.com/questions/22267136/best-practise-in-spa-hash-vs-questionmark-url

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