X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/angular2/src/router/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}


Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/router/route_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 20 additions & 1 deletion modules/angular2/test/router/integration/redirect_route_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}));
});
}
X Tutup