diff --git a/modules/angular2/src/router/instruction.ts b/modules/angular2/src/router/instruction.ts index 815745bd92..817e91a56d 100644 --- a/modules/angular2/src/router/instruction.ts +++ b/modules/angular2/src/router/instruction.ts @@ -281,9 +281,11 @@ export class UnresolvedInstruction extends Instruction { export class RedirectInstruction extends ResolvedInstruction { constructor(component: ComponentInstruction, child: Instruction, - auxInstruction: {[key: string]: Instruction}) { + auxInstruction: {[key: string]: Instruction}, private _specificity: string) { super(component, child, auxInstruction); } + + get specificity(): string { return this._specificity; } } diff --git a/modules/angular2/src/router/route_registry.ts b/modules/angular2/src/router/route_registry.ts index dbf757f4a7..5750396c29 100644 --- a/modules/angular2/src/router/route_registry.ts +++ b/modules/angular2/src/router/route_registry.ts @@ -205,7 +205,7 @@ export class RouteRegistry { var instruction = this.generate(candidate.redirectTo, ancestorInstructions.concat([null])); return new RedirectInstruction(instruction.component, instruction.child, - instruction.auxInstruction); + instruction.auxInstruction, candidate.specificity); } })); diff --git a/modules/angular2/test/router/integration/impl/fixture_components.ts b/modules/angular2/test/router/integration/impl/fixture_components.ts index 075213bdf6..5777bf163b 100644 --- a/modules/angular2/test/router/integration/impl/fixture_components.ts +++ b/modules/angular2/test/router/integration/impl/fixture_components.ts @@ -10,6 +10,12 @@ import { } from 'angular2/router'; import {PromiseWrapper} from 'angular2/src/facade/async'; +@Component({selector: 'goodbye-cmp', template: `{{farewell}}`}) +export class GoodbyeCmp { + farewell: string; + constructor() { this.farewell = 'goodbye'; } +} + @Component({selector: 'hello-cmp', template: `{{greeting}}`}) export class HelloCmp { greeting: string; diff --git a/modules/angular2/test/router/integration/redirect_route_spec.ts b/modules/angular2/test/router/integration/redirect_route_spec.ts index 4c2f195b3d..963fc78e30 100644 --- a/modules/angular2/test/router/integration/redirect_route_spec.ts +++ b/modules/angular2/test/router/integration/redirect_route_spec.ts @@ -25,7 +25,7 @@ import { } from 'angular2/src/router/route_config_decorator'; import {TEST_ROUTER_PROVIDERS, RootCmp, compile} from './util'; -import {HelloCmp, RedirectToParentCmp} from './impl/fixture_components'; +import {HelloCmp, GoodbyeCmp, RedirectToParentCmp} from './impl/fixture_components'; var cmpInstanceCount; var childCmpInstanceCount; @@ -117,5 +117,24 @@ export function main() { async.done(); }); })); + + + it('should not redirect when redirect is less specific than other matching routes', + inject([AsyncTestCompleter, Location], (async, location) => { + compile(tcb) + .then((rtc) => {rootTC = rtc}) + .then((_) => rtr.config([ + new Route({path: '/foo', component: HelloCmp, name: 'Hello'}), + new Route({path: '/:param', component: GoodbyeCmp, name: 'Goodbye'}), + new Redirect({path: '/*rest', redirectTo: ['/Hello']}) + ])) + .then((_) => rtr.navigateByUrl('/bye')) + .then((_) => { + rootTC.detectChanges(); + expect(rootTC.debugElement.nativeElement).toHaveText('goodbye'); + expect(location.urlChanges).toEqual(['/bye']); + async.done(); + }); + })); }); }