parent
23784a2eca
commit
0ebe283b37
|
@ -38,16 +38,15 @@ export class Route implements RouteDefinition {
|
||||||
path: string;
|
path: string;
|
||||||
component: Type;
|
component: Type;
|
||||||
name: string;
|
name: string;
|
||||||
// added next two properties to work around https://github.com/Microsoft/TypeScript/issues/4107
|
// added next three properties to work around https://github.com/Microsoft/TypeScript/issues/4107
|
||||||
loader: Function;
|
aux: string = null;
|
||||||
redirectTo: string;
|
loader: Function = null;
|
||||||
|
redirectTo: string = null;
|
||||||
constructor({path, component, name,
|
constructor({path, component, name,
|
||||||
data}: {path: string, component: Type, name?: string, data?: {[key: string]: any}}) {
|
data}: {path: string, component: Type, name?: string, data?: {[key: string]: any}}) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.component = component;
|
this.component = component;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.loader = null;
|
|
||||||
this.redirectTo = null;
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +77,8 @@ export class AuxRoute implements RouteDefinition {
|
||||||
path: string;
|
path: string;
|
||||||
component: Type;
|
component: Type;
|
||||||
name: string;
|
name: string;
|
||||||
// added next two properties to work around https://github.com/Microsoft/TypeScript/issues/4107
|
// added next three properties to work around https://github.com/Microsoft/TypeScript/issues/4107
|
||||||
|
aux: string = null;
|
||||||
loader: Function = null;
|
loader: Function = null;
|
||||||
redirectTo: string = null;
|
redirectTo: string = null;
|
||||||
constructor({path, component, name}: {path: string, component: Type, name?: string}) {
|
constructor({path, component, name}: {path: string, component: Type, name?: string}) {
|
||||||
|
@ -115,6 +115,7 @@ export class AsyncRoute implements RouteDefinition {
|
||||||
path: string;
|
path: string;
|
||||||
loader: Function;
|
loader: Function;
|
||||||
name: string;
|
name: string;
|
||||||
|
aux: string = null;
|
||||||
constructor({path, loader, name, data}:
|
constructor({path, loader, name, data}:
|
||||||
{path: string, loader: Function, name?: string, data?: {[key: string]: any}}) {
|
{path: string, loader: Function, name?: string, data?: {[key: string]: any}}) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
@ -148,9 +149,10 @@ export class Redirect implements RouteDefinition {
|
||||||
path: string;
|
path: string;
|
||||||
redirectTo: string;
|
redirectTo: string;
|
||||||
name: string = null;
|
name: string = null;
|
||||||
// added next property to work around https://github.com/Microsoft/TypeScript/issues/4107
|
// added next three properties to work around https://github.com/Microsoft/TypeScript/issues/4107
|
||||||
loader: Function = null;
|
loader: Function = null;
|
||||||
data: any = null;
|
data: any = null;
|
||||||
|
aux: string = null;
|
||||||
constructor({path, redirectTo}: {path: string, redirectTo: string}) {
|
constructor({path, redirectTo}: {path: string, redirectTo: string}) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.redirectTo = redirectTo;
|
this.redirectTo = redirectTo;
|
||||||
|
|
|
@ -26,6 +26,9 @@ export function normalizeRouteConfig(config: RouteDefinition): RouteDefinition {
|
||||||
if (config.loader) {
|
if (config.loader) {
|
||||||
return new AsyncRoute({path: config.path, loader: config.loader, name: config.name});
|
return new AsyncRoute({path: config.path, loader: config.loader, name: config.name});
|
||||||
}
|
}
|
||||||
|
if (config.aux) {
|
||||||
|
return new AuxRoute({path: config.aux, component:<Type>config.component, name: config.name});
|
||||||
|
}
|
||||||
if (config.component) {
|
if (config.component) {
|
||||||
if (typeof config.component == 'object') {
|
if (typeof config.component == 'object') {
|
||||||
let componentDefinitionObject = <ComponentDefinition>config.component;
|
let componentDefinitionObject = <ComponentDefinition>config.component;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {CONST, Type} from 'angular2/src/core/facade/lang';
|
||||||
* `RouteDefinition` defines a route within a {@link RouteConfig} decorator.
|
* `RouteDefinition` defines a route within a {@link RouteConfig} decorator.
|
||||||
*
|
*
|
||||||
* Supported keys:
|
* Supported keys:
|
||||||
* - `path` (required)
|
* - `path` or `aux` (requires exactly one of these)
|
||||||
* - `component`, `loader`, `redirectTo` (requires exactly one of these)
|
* - `component`, `loader`, `redirectTo` (requires exactly one of these)
|
||||||
* - `name` or `as` (optional) (requires exactly one of these)
|
* - `name` or `as` (optional) (requires exactly one of these)
|
||||||
* - `data` (optional)
|
* - `data` (optional)
|
||||||
|
@ -12,7 +12,8 @@ import {CONST, Type} from 'angular2/src/core/facade/lang';
|
||||||
* See also {@link Route}, {@link AsyncRoute}, {@link AuxRoute}, and {@link Redirect}.
|
* See also {@link Route}, {@link AsyncRoute}, {@link AuxRoute}, and {@link Redirect}.
|
||||||
*/
|
*/
|
||||||
export interface RouteDefinition {
|
export interface RouteDefinition {
|
||||||
path: string;
|
path?: string;
|
||||||
|
aux?: string;
|
||||||
component?: Type | ComponentDefinition;
|
component?: Type | ComponentDefinition;
|
||||||
loader?: Function;
|
loader?: Function;
|
||||||
redirectTo?: string;
|
redirectTo?: string;
|
||||||
|
|
|
@ -337,8 +337,11 @@ export class Router {
|
||||||
}
|
}
|
||||||
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
this._auxRouters.forEach(
|
this._auxRouters.forEach((router, name) => {
|
||||||
(router, name) => { promises.push(router.commit(instruction.auxInstruction[name])); });
|
if (isPresent(instruction.auxInstruction[name])) {
|
||||||
|
promises.push(router.commit(instruction.auxInstruction[name]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return next.then((_) => PromiseWrapper.all(promises));
|
return next.then((_) => PromiseWrapper.all(promises));
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,20 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should work in an app with aux routes', inject([AsyncTestCompleter], (async) => {
|
||||||
|
bootstrap(AuxAppCmp, testBindings)
|
||||||
|
.then((applicationRef) => {
|
||||||
|
var router = applicationRef.hostComponent.router;
|
||||||
|
router.subscribe((_) => {
|
||||||
|
expect(el).toHaveText('root { hello } aside { hello }');
|
||||||
|
expect(applicationRef.hostComponent.location.path()).toEqual('/hello(aside)');
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
router.navigateByUrl('/hello(aside)');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should work in an app with async components defined with "loader"',
|
it('should work in an app with async components defined with "loader"',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
bootstrap(ConciseAsyncAppCmp, testBindings)
|
bootstrap(ConciseAsyncAppCmp, testBindings)
|
||||||
|
@ -227,6 +241,13 @@ class ConciseAsyncAppCmp {
|
||||||
constructor(public router: Router, public location: LocationStrategy) {}
|
constructor(public router: Router, public location: LocationStrategy) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Component({selector: 'app-cmp'})
|
||||||
|
@View({template: `root { <router-outlet></router-outlet> } aside { <router-outlet name="aside"></router-outlet> }`, directives: ROUTER_DIRECTIVES})
|
||||||
|
@RouteConfig([{path: '/hello', component: HelloCmp}, {aux: 'aside', component: HelloCmp}])
|
||||||
|
class AuxAppCmp {
|
||||||
|
constructor(public router: Router, public location: LocationStrategy) {}
|
||||||
|
}
|
||||||
|
|
||||||
@Component({selector: 'app-cmp'})
|
@Component({selector: 'app-cmp'})
|
||||||
@View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
|
@View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
|
||||||
@RouteConfig([
|
@RouteConfig([
|
||||||
|
|
Loading…
Reference in New Issue