diff --git a/src/urlRouter.js b/src/urlRouter.js index 33c17090f..05ef8dc81 100644 --- a/src/urlRouter.js +++ b/src/urlRouter.js @@ -262,8 +262,8 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) { * */ this.$get = $get; - $get.$inject = ['$location', '$rootScope', '$injector', '$browser']; - function $get( $location, $rootScope, $injector, $browser) { + $get.$inject = ['$location', '$rootScope', '$injector', '$browser', '$sniffer']; + function $get( $location, $rootScope, $injector, $browser, $sniffer) { var baseHref = $browser.baseHref(), location = $location.url(), lastPushedUrl; @@ -396,6 +396,8 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) { if (angular.isObject(isHtml5)) { isHtml5 = isHtml5.enabled; } + + isHtml5 = isHtml5 && $sniffer.history; var url = urlMatcher.format(params); options = options || {}; diff --git a/test/urlRouterSpec.js b/test/urlRouterSpec.js index d25d14105..ab916c051 100644 --- a/test/urlRouterSpec.js +++ b/test/urlRouterSpec.js @@ -1,7 +1,6 @@ describe("UrlRouter", function () { - var $urp, $lp, $ur, location, match, scope; - + var $urp, $lp, $s, $ur, location, match, scope; describe("provider", function () { beforeEach(function() { @@ -67,6 +66,8 @@ describe("UrlRouter", function () { scope = $rootScope.$new(); location = $location; $ur = $injector.invoke($urp.$get); + $s = $injector.get('$sniffer'); + $s.history = true; }); }); @@ -236,6 +237,13 @@ describe("UrlRouter", function () { expect($lp.html5Mode()).toBe(true); expect($urlRouter.href(new UrlMatcher('/hello/:name'), {name: 'world', '#': 'frag'})).toBe('/hello/world#frag'); })); + + it('should return URLs with #fragments when html5Mode is true & browser does not support pushState', inject(function($urlRouter) { + $lp.html5Mode(true); + $s.history = false; + expect($lp.html5Mode()).toBe(true); + expect($urlRouter.href(new UrlMatcher('/hello/:name'), {name: 'world', '#': 'frag'})).toBe('#/hello/world#frag'); + })); }); });