How single page apps with good usability work
If you want to increase user experience and usability factor of your page, you should be using page hashing/fragments. I'm not going to provide the same (or similar) code that others did, but rather upgrade the experience.
So how about that UX then
Your single-page web application should be changing hash every time when it changes context of its work. That may be defined by user interface or business process that user does in the UI or maybe even individual steps of such processes when it's expected that users would/should be going back to previous process states.
This way your application would function similar to normal web applications that consist of several pages and create a new history entry on the same basis of business processes and their steps (steps in this case are usually full-page postbacks).
So business processes and thinking of your application as a normal multi-page one will give you many useful points when you may change page fragment. Since you can control this you can provide better granularity (usually less) than multi-page web applications.
A simple example where multi-page application history has too many points
Form posts are usually always problematic, so having a history point after postback response is always bad because users hitting F5 resend the same form over and over again (ok browsers do ask you about resending post data but that's still bad experience).
Page fragmenting is the way to go, just use it further than just preventing getting back to logon page.
Completely preventing logon page getting into history stack would be by displaying it on your page within an iframe
. You would of course need to detect unauthenticated user and add the iframe
yourself and load login in it. After user authenticates you should reload your own page. But you should be aware that detecting login success won't be a straight-forward process.