Created
October 4, 2012 16:21
-
-
Save thomseddon/3834721 to your computer and use it in GitHub Desktop.
AngularJS: Avoid redirection loop in legacy browser (IE) with HTML5 mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('!'); |
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
Thank you for sharing this! :)