fix(router): absolute redirects should work with lazy loading

This commit is contained in:
vsavkin
2016-08-04 18:56:22 -07:00
committed by Alex Rickabaugh
parent 4f17dbc721
commit 3a307c2794
5 changed files with 218 additions and 211 deletions

View File

@ -251,6 +251,21 @@ describe('applyRedirects', () => {
(r) => { compareTrees(r, tree('/a/b')); }, (e) => { throw 'Should not reach'; });
});
it('should work with absolute redirects', () => {
const loadedConfig = new LoadedRouterConfig(
[{path: '', component: ComponentB}], <any>'stubInjector', <any>'stubFactoryResolver');
const loader = {load: (injector: any, p: any) => of (loadedConfig)};
const config =
[{path: '', pathMatch: 'full', redirectTo: '/a'}, {path: 'a', loadChildren: 'children'}];
applyRedirects(<any>'providedInjector', <any>loader, tree(''), config).forEach(r => {
compareTrees(r, tree('a'));
expect((<any>config[1])._loadedConfig).toBe(loadedConfig);
});
});
});
describe('empty paths', () => {

View File

@ -13,7 +13,7 @@ import {ActivatedRoute, ActivatedRouteSnapshot, advanceActivatedRoute} from '../
import {PRIMARY_OUTLET, Params} from '../src/shared';
import {DefaultUrlSerializer, UrlSegment, UrlSegmentGroup, UrlTree} from '../src/url_tree';
fdescribe('createUrlTree', () => {
describe('createUrlTree', () => {
const serializer = new DefaultUrlSerializer();
it('should navigate to the root', () => {

View File

@ -259,19 +259,6 @@ describe('recognize', () => {
});
});
it('should not match when terminal', () => {
recognize(
RootComponent, [{
path: '',
pathMatch: 'full',
component: ComponentA,
children: [{path: 'b', component: ComponentB}]
}],
tree('b'), '')
.subscribe(
() => {}, (e) => { expect(e.message).toEqual('Cannot match any routes: \'b\''); });
});
it('should work (nested case)', () => {
checkRecognize(
[{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], '',
@ -678,20 +665,6 @@ describe('recognize', () => {
'Two segments cannot have the same outlet name: \'aux:b\' and \'aux:c\'.');
});
});
it('should error when no matching routes', () => {
recognize(RootComponent, [{path: 'a', component: ComponentA}], tree('invalid'), 'invalid')
.subscribe((_) => {}, (s: RouterStateSnapshot) => {
expect(s.toString()).toContain('Cannot match any routes');
});
});
it('should error when no matching routes (too short)', () => {
recognize(RootComponent, [{path: 'a/:id', component: ComponentA}], tree('a'), 'a')
.subscribe((_) => {}, (s: RouterStateSnapshot) => {
expect(s.toString()).toContain('Cannot match any routes');
});
});
});
});