Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/urlRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 || {};
Expand Down
12 changes: 10 additions & 2 deletions test/urlRouterSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
describe("UrlRouter", function () {

var $urp, $lp, $ur, location, match, scope;

var $urp, $lp, $s, $ur, location, match, scope;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You deleted these other variables accidentally

describe("provider", function () {

beforeEach(function() {
Expand Down Expand Up @@ -67,6 +66,8 @@ describe("UrlRouter", function () {
scope = $rootScope.$new();
location = $location;
$ur = $injector.invoke($urp.$get);
$s = $injector.get('$sniffer');
$s.history = true;
});
});

Expand Down Expand Up @@ -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');
}));
});
});

Expand Down