Rework 'back' functionality.

It's pretty important that our 'back' doesn't work just like the
browser's history.back() so that we don't get stuck in unecessary
loops. Particularly after using something like the search form.

To that end I've replaced the existing history.back() and
history.replaceState() stuff with a kind of 'curated' history which
should just contain the visited and activated URLs that we care about.