Skip to content

Instantly share code, notes, and snippets.

@thomseddon
Created October 4, 2012 16:21
Show Gist options
  • Save thomseddon/3834721 to your computer and use it in GitHub Desktop.
Save thomseddon/3834721 to your computer and use it in GitHub Desktop.
AngularJS: Avoid redirection loop in legacy browser (IE) with HTML5 mode
var buggyAndroid = parseInt((/android (\d+)/.exec(window.navigator.userAgent.toLowerCase()) || [])[1], 10) < 4;
if (!history.pushState || buggyAndroid) {
if (window.location.hash) {
if(window.location.pathname !== '/') window.location.replace('/#!' + window.location.hash.substr(2)); //Hash and a path, just keep the hash (redirect)
} else {
window.location.replace('/#!' + window.location.pathname); //No hash, take path
}
}
//And then in app.config:
//$locationProvider.html5Mode(true).hashPrefix('!');
@voltechs
Copy link

Where does the initial if statement go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment