fix(router): don't prepend `/` unnecessarily to Location paths
Closes #6729 Closes #5502
This commit is contained in:
parent
d86be245b8
commit
c6036435f0
|
@ -131,6 +131,26 @@ describe('navigation', function () {
|
||||||
expect(elt.text()).toBe('outer { inner { one } }');
|
expect(elt.text()).toBe('outer { inner { one } }');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should work when parent route has empty path', inject(function ($location) {
|
||||||
|
registerComponent('childCmp', {
|
||||||
|
template: '<div>inner { <div ng-outlet></div> }</div>',
|
||||||
|
$routeConfig: [
|
||||||
|
{ path: '/b', component: 'oneCmp' }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
$router.config([
|
||||||
|
{ path: '/...', component: 'childCmp' }
|
||||||
|
]);
|
||||||
|
compile('<div>outer { <div ng-outlet></div> }</div>');
|
||||||
|
|
||||||
|
$router.navigateByUrl('/b');
|
||||||
|
$rootScope.$digest();
|
||||||
|
|
||||||
|
expect(elt.text()).toBe('outer { inner { one } }');
|
||||||
|
expect($location.path()).toBe('/b');
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should work with recursive nested outlets', function () {
|
it('should work with recursive nested outlets', function () {
|
||||||
registerDirective('recurCmp', {
|
registerDirective('recurCmp', {
|
||||||
|
|
|
@ -438,7 +438,7 @@ export class RootRouter extends Router {
|
||||||
}
|
}
|
||||||
var emitPath = instruction.toUrlPath();
|
var emitPath = instruction.toUrlPath();
|
||||||
var emitQuery = instruction.toUrlQuery();
|
var emitQuery = instruction.toUrlQuery();
|
||||||
if (emitPath.length > 0) {
|
if (emitPath.length > 0 && emitPath[0] != '/') {
|
||||||
emitPath = '/' + emitPath;
|
emitPath = '/' + emitPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,7 +465,7 @@ export class RootRouter extends Router {
|
||||||
commit(instruction: Instruction, _skipLocationChange: boolean = false): Promise<any> {
|
commit(instruction: Instruction, _skipLocationChange: boolean = false): Promise<any> {
|
||||||
var emitPath = instruction.toUrlPath();
|
var emitPath = instruction.toUrlPath();
|
||||||
var emitQuery = instruction.toUrlQuery();
|
var emitQuery = instruction.toUrlQuery();
|
||||||
if (emitPath.length > 0) {
|
if (emitPath.length > 0 && emitPath[0] != '/') {
|
||||||
emitPath = '/' + emitPath;
|
emitPath = '/' + emitPath;
|
||||||
}
|
}
|
||||||
var promise = super.commit(instruction);
|
var promise = super.commit(instruction);
|
||||||
|
|
|
@ -105,6 +105,20 @@ export function main() {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should navigate to child routes when the root component has an empty path',
|
||||||
|
inject([AsyncTestCompleter, Location], (async, location) => {
|
||||||
|
compile(tcb, 'outer { <router-outlet></router-outlet> }')
|
||||||
|
.then((rtc) => {fixture = rtc})
|
||||||
|
.then((_) => rtr.config([new Route({path: '/...', component: ParentCmp})]))
|
||||||
|
.then((_) => rtr.navigateByUrl('/b'))
|
||||||
|
.then((_) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
|
||||||
|
expect(location.urlChanges).toEqual(['/b']);
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should navigate to child routes of async routes', inject([AsyncTestCompleter], (async) => {
|
it('should navigate to child routes of async routes', inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb, 'outer { <router-outlet></router-outlet> }')
|
compile(tcb, 'outer { <router-outlet></router-outlet> }')
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
|
|
Loading…
Reference in New Issue