From 7fea1e9d0d8c6e09cc6c895ecb93d4221e9adf48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Garc=C3=ADa=20Sanz?= Date: Thu, 25 Sep 2014 18:26:32 +0200 Subject: [PATCH] fix(urlRouter): html5Mode accepts an object from angular v1.3.0-rc.3 Since https://github.com/angular/angular.js/commit/dc3de7fb7a14c38b5c3dc7decfafb0b51d422dd1 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 https://github.com/angular-ui/ui-router/issues/1397 --- src/urlRouter.js | 4 ++++ test/urlRouterSpec.js | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/urlRouter.js b/src/urlRouter.js index 5bdb58ff8..4e5fbc4a2 100644 --- a/src/urlRouter.js +++ b/src/urlRouter.js @@ -381,6 +381,10 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) { if (!urlMatcher.validates(params)) return null; var isHtml5 = $locationProvider.html5Mode(); + if (angular.isObject(isHtml5)) { + isHtml5 = isHtml5.enabled; + } + var url = urlMatcher.format(params); options = options || {}; diff --git a/test/urlRouterSpec.js b/test/urlRouterSpec.js index 8cc41698f..f0235ecb2 100644 --- a/test/urlRouterSpec.js +++ b/test/urlRouterSpec.js @@ -1,6 +1,6 @@ describe("UrlRouter", function () { - var $urp, $ur, location, match, scope; + var $urp, $lp, $ur, location, match, scope; describe("provider", function () { @@ -46,8 +46,9 @@ describe("UrlRouter", function () { describe("service", function() { beforeEach(function() { - angular.module('ui.router.router.test', function() {}).config(function ($urlRouterProvider) { + angular.module('ui.router.router.test', function() {}).config(function ($urlRouterProvider, $locationProvider) { $urp = $urlRouterProvider; + $lp = $locationProvider; $urp.rule(function ($injector, $location) { var path = $location.path(); @@ -198,6 +199,15 @@ describe("UrlRouter", function () { expect($urlRouter.href(matcher, { param: 1138 })).toBe('#/foo/1138'); expect($urlRouter.href(matcher, { param: 5 })).toBeNull(); })); + + it('should handle the new html5Mode object config from Angular 1.3', inject(function($urlRouter) { + + $lp.html5Mode({ + enabled: false + }); + + expect($urlRouter.href(new UrlMatcher('/hello'))).toBe('#/hello'); + })); }); });