From df7885c9f51b77161cb687deeeda918a5083ebf7 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Sun, 31 Jan 2016 14:52:19 -0600 Subject: [PATCH] fix(router): Added route data to normalized async route Closes #6802 --- .../test/integration/router_spec.js | 25 +++++++++++++++++-- .../src/router/route_config_nomalizer.ts | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/angular1_router/test/integration/router_spec.js b/modules/angular1_router/test/integration/router_spec.js index bea802f366..00a2385fc4 100644 --- a/modules/angular1_router/test/integration/router_spec.js +++ b/modules/angular1_router/test/integration/router_spec.js @@ -44,7 +44,6 @@ describe('router', function () { expect(elt.text()).toBe('Home'); })); - it('should bind the component to the current router', inject(function($location) { var router; registerComponent('homeCmp', { @@ -74,6 +73,28 @@ describe('router', function () { expect(router).toBeDefined(); })); + it('should work when an async route is provided route data', inject(function($location, $q) { + registerDirective('homeCmp', { + template: 'Home ({{homeCmp.isAdmin}})', + $routerOnActivate: function(next, prev) { + this.isAdmin = next.routeData.data.isAdmin; + } + }); + + registerDirective('app', { + template: '
', + $routeConfig: [ + { path: '/', loader: function() { return $q.when('homeCmp'); }, data: { isAdmin: true } } + ] + }); + + compile(''); + + $location.path('/'); + $rootScope.$digest(); + expect(elt.text()).toBe('Home (true)'); + })); + function registerDirective(name, options) { function factory() { return { @@ -124,4 +145,4 @@ describe('router', function () { } }); } -}); \ No newline at end of file +}); diff --git a/modules/angular2/src/router/route_config_nomalizer.ts b/modules/angular2/src/router/route_config_nomalizer.ts index 16518fa79f..cd666e6b35 100644 --- a/modules/angular2/src/router/route_config_nomalizer.ts +++ b/modules/angular2/src/router/route_config_nomalizer.ts @@ -44,6 +44,7 @@ export function normalizeRouteConfig(config: RouteDefinition, path: config.path, loader: wrappedLoader, name: config.name, + data: config.data, useAsDefault: config.useAsDefault }); } @@ -66,6 +67,7 @@ export function normalizeRouteConfig(config: RouteDefinition, path: config.path, loader: componentDefinitionObject.loader, name: config.name, + data: config.data, useAsDefault: config.useAsDefault }); } else {