X Tutup
Skip to content

Commit df7885c

Browse files
fix(router): Added route data to normalized async route
Closes #6802
1 parent 0f10624 commit df7885c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

modules/angular1_router/test/integration/router_spec.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ describe('router', function () {
4444
expect(elt.text()).toBe('Home');
4545
}));
4646

47-
4847
it('should bind the component to the current router', inject(function($location) {
4948
var router;
5049
registerComponent('homeCmp', {
@@ -74,6 +73,28 @@ describe('router', function () {
7473
expect(router).toBeDefined();
7574
}));
7675

76+
it('should work when an async route is provided route data', inject(function($location, $q) {
77+
registerDirective('homeCmp', {
78+
template: 'Home ({{homeCmp.isAdmin}})',
79+
$routerOnActivate: function(next, prev) {
80+
this.isAdmin = next.routeData.data.isAdmin;
81+
}
82+
});
83+
84+
registerDirective('app', {
85+
template: '<div ng-outlet></div>',
86+
$routeConfig: [
87+
{ path: '/', loader: function() { return $q.when('homeCmp'); }, data: { isAdmin: true } }
88+
]
89+
});
90+
91+
compile('<app></app>');
92+
93+
$location.path('/');
94+
$rootScope.$digest();
95+
expect(elt.text()).toBe('Home (true)');
96+
}));
97+
7798
function registerDirective(name, options) {
7899
function factory() {
79100
return {
@@ -124,4 +145,4 @@ describe('router', function () {
124145
}
125146
});
126147
}
127-
});
148+
});

modules/angular2/src/router/route_config_nomalizer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function normalizeRouteConfig(config: RouteDefinition,
4444
path: config.path,
4545
loader: wrappedLoader,
4646
name: config.name,
47+
data: config.data,
4748
useAsDefault: config.useAsDefault
4849
});
4950
}
@@ -66,6 +67,7 @@ export function normalizeRouteConfig(config: RouteDefinition,
6667
path: config.path,
6768
loader: componentDefinitionObject.loader,
6869
name: config.name,
70+
data: config.data,
6971
useAsDefault: config.useAsDefault
7072
});
7173
} else {

0 commit comments

Comments
 (0)
X Tutup