Skip to content

Commit 7fea1e9

Browse files
committed
fix(urlRouter): html5Mode accepts an object from angular v1.3.0-rc.3
Since angular/angular.js@dc3de7f angular accepts both boolean and objects like {enabled: true, requireBase: false} causing the evaluation to be always true. In order to allow the use of ui-router with angular 1.3 a fix has been made, it checks if the value is an object and gets its enabled property value. Fixes #1397
1 parent 06d53a3 commit 7fea1e9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/urlRouter.js

+4
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
381381
if (!urlMatcher.validates(params)) return null;
382382

383383
var isHtml5 = $locationProvider.html5Mode();
384+
if (angular.isObject(isHtml5)) {
385+
isHtml5 = isHtml5.enabled;
386+
}
387+
384388
var url = urlMatcher.format(params);
385389
options = options || {};
386390

test/urlRouterSpec.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe("UrlRouter", function () {
22

3-
var $urp, $ur, location, match, scope;
3+
var $urp, $lp, $ur, location, match, scope;
44

55
describe("provider", function () {
66

@@ -46,8 +46,9 @@ describe("UrlRouter", function () {
4646
describe("service", function() {
4747

4848
beforeEach(function() {
49-
angular.module('ui.router.router.test', function() {}).config(function ($urlRouterProvider) {
49+
angular.module('ui.router.router.test', function() {}).config(function ($urlRouterProvider, $locationProvider) {
5050
$urp = $urlRouterProvider;
51+
$lp = $locationProvider;
5152

5253
$urp.rule(function ($injector, $location) {
5354
var path = $location.path();
@@ -198,6 +199,15 @@ describe("UrlRouter", function () {
198199
expect($urlRouter.href(matcher, { param: 1138 })).toBe('#/foo/1138');
199200
expect($urlRouter.href(matcher, { param: 5 })).toBeNull();
200201
}));
202+
203+
it('should handle the new html5Mode object config from Angular 1.3', inject(function($urlRouter) {
204+
205+
$lp.html5Mode({
206+
enabled: false
207+
});
208+
209+
expect($urlRouter.href(new UrlMatcher('/hello'))).toBe('#/hello');
210+
}));
201211
});
202212
});
203213

0 commit comments

Comments
 (0)