diff --git a/modules/angular1_router/src/module_template.js b/modules/angular1_router/src/module_template.js index 6712ca77c8..43415af4d5 100644 --- a/modules/angular1_router/src/module_template.js +++ b/modules/angular1_router/src/module_template.js @@ -1,9 +1,12 @@ angular.module('ngComponentRouter'). value('$route', null). // can be overloaded with ngRouteShim - factory('$router', ['$q', '$location', '$$directiveIntrospector', '$browser', '$rootScope', '$injector', routerFactory]); + // Because Angular 1 has no notion of a root component, we use an object with unique identity + // to represent this. Can be overloaded with a component name + value('$routerRootComponent', new Object()). + factory('$router', ['$q', '$location', '$$directiveIntrospector', '$browser', '$rootScope', '$injector', '$routerRootComponent', routerFactory]); -function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootScope, $injector) { +function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootScope, $injector, $routerRootComponent) { // When this file is processed, the line below is replaced with // the contents of `../lib/facades.es5`. @@ -42,12 +45,7 @@ function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootSc var RouteRegistry = exports.RouteRegistry; var RootRouter = exports.RootRouter; - - // Because Angular 1 has no notion of a root component, we use an object with unique identity - // to represent this. - var ROOT_COMPONENT_OBJECT = new Object(); - - var registry = new RouteRegistry(ROOT_COMPONENT_OBJECT); + var registry = new RouteRegistry($routerRootComponent); var location = new Location(); $$directiveIntrospector(function (name, factory) { @@ -58,7 +56,7 @@ function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootSc } }); - var router = new RootRouter(registry, location, ROOT_COMPONENT_OBJECT); + var router = new RootRouter(registry, location, $routerRootComponent); $rootScope.$watch(function () { return $location.path(); }, function (path) { if (router.lastNavigationAttempt !== path) { router.navigateByUrl(path); diff --git a/modules/angular1_router/test/integration/router_spec.js b/modules/angular1_router/test/integration/router_spec.js new file mode 100644 index 0000000000..c302c21cea --- /dev/null +++ b/modules/angular1_router/test/integration/router_spec.js @@ -0,0 +1,79 @@ +'use strict'; + +describe('router', function () { + + var elt, + $compile, + $rootScope, + $router, + $compileProvider; + + beforeEach(function () { + module('ng'); + module('ngComponentRouter'); + module(function($provide) { + $provide.value('$routerRootComponent', 'app'); + }); + module(function (_$compileProvider_) { + $compileProvider = _$compileProvider_; + }); + + inject(function (_$compile_, _$rootScope_, _$router_) { + $compile = _$compile_; + $rootScope = _$rootScope_; + $router = _$router_; + }); + }); + + it('should work with a provided root component', inject(function($location) { + registerComponent('homeCmp', { + template: 'Home' + }); + + registerComponent('app', { + template: '
', + $routeConfig: [ + { path: '/', component: 'homeCmp' } + ] + }); + + compile('