diff --git a/src/ng/browser.js b/src/ng/browser.js index 3925348317ce..245b6417ce6d 100644 --- a/src/ng/browser.js +++ b/src/ng/browser.js @@ -29,7 +29,8 @@ function Browser(window, document, $log, $sniffer) { history = window.history, setTimeout = window.setTimeout, clearTimeout = window.clearTimeout, - pendingDeferIds = {}; + pendingDeferIds = {}, + useHtml5HistoryMode = false; self.isMock = false; @@ -151,7 +152,7 @@ function Browser(window, document, $log, $sniffer) { if (url) { if (lastBrowserUrl == url) return; lastBrowserUrl = url; - if ($sniffer.history) { + if ($sniffer.history && useHtml5HistoryMode) { if (replace) history.replaceState(null, '', url); else { history.pushState(null, '', url); @@ -212,7 +213,7 @@ function Browser(window, document, $log, $sniffer) { // changed by push/replaceState // html5 history api - popstate event - if ($sniffer.history) jqLite(window).bind('popstate', fireUrlChange); + if ($sniffer.history && useHtml5HistoryMode) jqLite(window).bind('popstate', fireUrlChange); // hashchange event if ($sniffer.hashchange) jqLite(window).bind('hashchange', fireUrlChange); // polling @@ -352,6 +353,15 @@ function Browser(window, document, $log, $sniffer) { return false; }; + self.html5HistoryMode = function(mode) { + if (isDefined(mode)) { + useHtml5HistoryMode = mode; + return this; + } else { + return useHtml5HistoryMode; + } + }; + } function $BrowserProvider(){ diff --git a/src/ng/location.js b/src/ng/location.js index cf50952d53c3..3c8b9752ba75 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -514,6 +514,9 @@ function $LocationProvider(){ initUrlParts = matchUrl(initUrl), appBaseUrl; + // Apply the html5Mode setting to the $browser service + $browser.html5HistoryMode(html5Mode); + if (html5Mode) { basePath = $browser.baseHref() || '/'; pathPrefix = pathPrefixFromBase(basePath);