refactor(router): drop the `InternalRoute` interface
This commit is contained in:
parent
886cca028f
commit
ea4afebeb9
|
@ -18,7 +18,7 @@ import {map} from 'rxjs/operator/map';
|
|||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {EmptyError} from 'rxjs/util/EmptyError';
|
||||
|
||||
import {InternalRoute, LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
import {PRIMARY_OUTLET, Params, defaultUrlMatcher, navigationCancelingError} from './shared';
|
||||
import {UrlSegment, UrlSegmentGroup, UrlSerializer, UrlTree} from './url_tree';
|
||||
|
@ -247,7 +247,7 @@ class ApplyRedirects {
|
|||
}
|
||||
|
||||
private matchSegmentAgainstRoute(
|
||||
ngModule: NgModuleRef<any>, rawSegmentGroup: UrlSegmentGroup, route: InternalRoute,
|
||||
ngModule: NgModuleRef<any>, rawSegmentGroup: UrlSegmentGroup, route: Route,
|
||||
segments: UrlSegment[]): Observable<UrlSegmentGroup> {
|
||||
if (route.path === '**') {
|
||||
if (route.loadChildren) {
|
||||
|
@ -292,8 +292,7 @@ class ApplyRedirects {
|
|||
});
|
||||
}
|
||||
|
||||
private getChildConfig(ngModule: NgModuleRef<any>, route: InternalRoute):
|
||||
Observable<LoadedRouterConfig> {
|
||||
private getChildConfig(ngModule: NgModuleRef<any>, route: Route): Observable<LoadedRouterConfig> {
|
||||
if (route.children) {
|
||||
// The children belong to the same module
|
||||
return of (new LoadedRouterConfig(route.children, ngModule));
|
||||
|
|
|
@ -357,7 +357,10 @@ export interface Route {
|
|||
children?: Routes;
|
||||
loadChildren?: LoadChildren;
|
||||
runGuardsAndResolvers?: RunGuardsAndResolvers;
|
||||
/** @internal */
|
||||
/**
|
||||
* Filled for routes with `loadChildren` once the module has been loaded
|
||||
* @internal
|
||||
*/
|
||||
_loadedConfig?: LoadedRouterConfig;
|
||||
}
|
||||
|
||||
|
@ -365,11 +368,6 @@ export class LoadedRouterConfig {
|
|||
constructor(public routes: Route[], public module: NgModuleRef<any>) {}
|
||||
}
|
||||
|
||||
export interface InternalRoute extends Route {
|
||||
// `LoadedRouterConfig` loaded via a Route `loadChildren`
|
||||
_loadedConfig?: LoadedRouterConfig;
|
||||
}
|
||||
|
||||
export function validateConfig(config: Routes, parentPath: string = ''): void {
|
||||
// forEach doesn't iterate undefined values
|
||||
for (let i = 0; i < config.length; i++) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import {Observable} from 'rxjs/Observable';
|
|||
import {Observer} from 'rxjs/Observer';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {Data, InternalRoute, ResolveData, Route, Routes} from './config';
|
||||
import {Data, ResolveData, Route, Routes} from './config';
|
||||
import {ActivatedRouteSnapshot, RouterStateSnapshot, inheritedParamsDataResolve} from './router_state';
|
||||
import {PRIMARY_OUTLET, defaultUrlMatcher} from './shared';
|
||||
import {UrlSegment, UrlSegmentGroup, UrlTree, mapChildrenIntoArray} from './url_tree';
|
||||
|
@ -154,7 +154,7 @@ function sortActivatedRouteSnapshots(nodes: TreeNode<ActivatedRouteSnapshot>[]):
|
|||
});
|
||||
}
|
||||
|
||||
function getChildConfig(route: InternalRoute): Route[] {
|
||||
function getChildConfig(route: Route): Route[] {
|
||||
if (route.children) {
|
||||
return route.children;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import {mergeMap} from 'rxjs/operator/mergeMap';
|
|||
import {reduce} from 'rxjs/operator/reduce';
|
||||
|
||||
import {applyRedirects} from './apply_redirects';
|
||||
import {InternalRoute, LoadedRouterConfig, QueryParamsHandling, ResolveData, Route, Routes, RunGuardsAndResolvers, validateConfig} from './config';
|
||||
import {LoadedRouterConfig, QueryParamsHandling, ResolveData, Route, Routes, RunGuardsAndResolvers, validateConfig} from './config';
|
||||
import {createRouterState} from './create_router_state';
|
||||
import {createUrlTree} from './create_url_tree';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
|
@ -1168,7 +1168,7 @@ function advanceActivatedRouteNodeAndItsChildren(node: TreeNode<ActivatedRoute>)
|
|||
|
||||
function parentLoadedConfig(snapshot: ActivatedRouteSnapshot): LoadedRouterConfig {
|
||||
for (let s = snapshot.parent; s; s = s.parent) {
|
||||
const route: InternalRoute = s._routeConfig;
|
||||
const route = s._routeConfig;
|
||||
if (route && route._loadedConfig) return route._loadedConfig;
|
||||
if (route && route.component) return null;
|
||||
}
|
||||
|
@ -1180,7 +1180,7 @@ function closestLoadedConfig(snapshot: ActivatedRouteSnapshot): LoadedRouterConf
|
|||
if (!snapshot) return null;
|
||||
|
||||
for (let s = snapshot.parent; s; s = s.parent) {
|
||||
const route: InternalRoute = s._routeConfig;
|
||||
const route = s._routeConfig;
|
||||
if (route && route._loadedConfig) return route._loadedConfig;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import {concatMap} from 'rxjs/operator/concatMap';
|
|||
import {filter} from 'rxjs/operator/filter';
|
||||
import {mergeAll} from 'rxjs/operator/mergeAll';
|
||||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {InternalRoute, LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {Event, NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart} from './events';
|
||||
import {Router} from './router';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
|
@ -100,8 +100,7 @@ export class RouterPreloader implements OnDestroy {
|
|||
|
||||
private processRoutes(ngModule: NgModuleRef<any>, routes: Routes): Observable<void> {
|
||||
const res: Observable<any>[] = [];
|
||||
for (const r of routes) {
|
||||
const route: InternalRoute = r;
|
||||
for (const route of routes) {
|
||||
// we already have the config loaded, just recurse
|
||||
if (route.loadChildren && !route.canLoad && route._loadedConfig) {
|
||||
const childConfig = route._loadedConfig;
|
||||
|
@ -119,7 +118,7 @@ export class RouterPreloader implements OnDestroy {
|
|||
return mergeAll.call(from(res));
|
||||
}
|
||||
|
||||
private preloadConfig(ngModule: NgModuleRef<any>, route: InternalRoute): Observable<void> {
|
||||
private preloadConfig(ngModule: NgModuleRef<any>, route: Route): Observable<void> {
|
||||
return this.preloadingStrategy.preload(route, () => {
|
||||
const loaded$ = this.loader.load(ngModule.injector, route);
|
||||
return mergeMap.call(loaded$, (config: LoadedRouterConfig) => {
|
||||
|
|
|
@ -162,12 +162,12 @@ describe('applyRedirects', () => {
|
|||
return of (loadedConfig);
|
||||
}
|
||||
};
|
||||
const config = [{path: 'a', component: ComponentA, loadChildren: 'children'}];
|
||||
const config: Routes = [{path: 'a', component: ComponentA, loadChildren: 'children'}];
|
||||
|
||||
applyRedirects(testModule.injector, <any>loader, serializer, tree('a/b'), config)
|
||||
.forEach(r => {
|
||||
compareTrees(r, tree('/a/b'));
|
||||
expect((<any>config[0])._loadedConfig).toBe(loadedConfig);
|
||||
expect(config[0]._loadedConfig).toBe(loadedConfig);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -289,12 +289,12 @@ describe('applyRedirects', () => {
|
|||
|
||||
const loader = {load: (injector: any, p: any) => of (loadedConfig)};
|
||||
|
||||
const config =
|
||||
const config: Routes =
|
||||
[{path: '', pathMatch: 'full', redirectTo: '/a'}, {path: 'a', loadChildren: 'children'}];
|
||||
|
||||
applyRedirects(testModule.injector, <any>loader, serializer, tree(''), config).forEach(r => {
|
||||
compareTrees(r, tree('a'));
|
||||
expect((<any>config[1])._loadedConfig).toBe(loadedConfig);
|
||||
expect(config[1]._loadedConfig).toBe(loadedConfig);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -310,7 +310,7 @@ describe('applyRedirects', () => {
|
|||
}
|
||||
};
|
||||
|
||||
const config = [{path: 'a', loadChildren: 'children'}];
|
||||
const config: Routes = [{path: 'a', loadChildren: 'children'}];
|
||||
|
||||
applyRedirects(testModule.injector, <any>loader, serializer, tree('a?k1'), config)
|
||||
.subscribe(r => {});
|
||||
|
@ -319,7 +319,7 @@ describe('applyRedirects', () => {
|
|||
.subscribe(
|
||||
r => {
|
||||
compareTrees(r, tree('a?k2'));
|
||||
expect((<any>config[0])._loadedConfig).toBe(loadedConfig);
|
||||
expect(config[0]._loadedConfig).toBe(loadedConfig);
|
||||
},
|
||||
(e) => { throw 'Should not reach'; });
|
||||
});
|
||||
|
@ -329,10 +329,10 @@ describe('applyRedirects', () => {
|
|||
|
||||
const loader = {load: (injector: any, p: any) => of (loadedConfig)};
|
||||
|
||||
const config = [{path: '**', loadChildren: 'children'}];
|
||||
const config: Routes = [{path: '**', loadChildren: 'children'}];
|
||||
|
||||
applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config)
|
||||
.forEach(r => { expect((<any>config[0])._loadedConfig).toBe(loadedConfig); });
|
||||
.forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); });
|
||||
});
|
||||
|
||||
it('should load the configuration after a local redirect from a wildcard route', () => {
|
||||
|
@ -340,11 +340,11 @@ describe('applyRedirects', () => {
|
|||
|
||||
const loader = {load: (injector: any, p: any) => of (loadedConfig)};
|
||||
|
||||
const config =
|
||||
const config: Routes =
|
||||
[{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: 'not-found'}];
|
||||
|
||||
applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config)
|
||||
.forEach(r => { expect((<any>config[0])._loadedConfig).toBe(loadedConfig); });
|
||||
.forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); });
|
||||
});
|
||||
|
||||
it('should load the configuration after an absolute redirect from a wildcard route', () => {
|
||||
|
@ -352,11 +352,11 @@ describe('applyRedirects', () => {
|
|||
|
||||
const loader = {load: (injector: any, p: any) => of (loadedConfig)};
|
||||
|
||||
const config =
|
||||
const config: Routes =
|
||||
[{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: '/not-found'}];
|
||||
|
||||
applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config)
|
||||
.forEach(r => { expect((<any>config[0])._loadedConfig).toBe(loadedConfig); });
|
||||
.forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); });
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -3049,7 +3049,7 @@ describe('Integration', () => {
|
|||
router.navigateByUrl('/blank');
|
||||
advance(fixture);
|
||||
|
||||
const config: any = router.config;
|
||||
const config = router.config;
|
||||
const firstConfig = config[1]._loadedConfig;
|
||||
|
||||
expect(firstConfig).toBeDefined();
|
||||
|
|
|
@ -10,7 +10,7 @@ import {Compiler, Component, NgModule, NgModuleFactoryLoader, NgModuleRef} from
|
|||
import {TestBed, fakeAsync, inject, tick} from '@angular/core/testing';
|
||||
|
||||
import {Route, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouterModule} from '../index';
|
||||
import {LoadedRouterConfig} from '../src/router_config_loader';
|
||||
import {LoadedRouterConfig} from '../src/config';
|
||||
import {PreloadAllModules, PreloadingStrategy, RouterPreloader} from '../src/router_preloader';
|
||||
import {RouterTestingModule, SpyNgModuleFactoryLoader} from '../testing';
|
||||
|
||||
|
@ -46,7 +46,7 @@ describe('RouterPreloader', () => {
|
|||
tick();
|
||||
|
||||
const c = router.config;
|
||||
expect(!!((<any>c[0])._loadedConfig)).toBe(false);
|
||||
expect(c[0]._loadedConfig).not.toBeDefined();
|
||||
})));
|
||||
});
|
||||
|
||||
|
@ -97,12 +97,12 @@ describe('RouterPreloader', () => {
|
|||
const c = router.config;
|
||||
expect(c[0].loadChildren).toEqual('expected');
|
||||
|
||||
const loadedConfig: LoadedRouterConfig = (<any>c[0])._loadedConfig;
|
||||
const loadedConfig: LoadedRouterConfig = c[0]._loadedConfig;
|
||||
const module: any = loadedConfig.module;
|
||||
expect(loadedConfig.routes[0].path).toEqual('LoadedModule1');
|
||||
expect(module.parent).toBe(testModule);
|
||||
|
||||
const loadedConfig2: LoadedRouterConfig = (<any>loadedConfig.routes[0])._loadedConfig;
|
||||
const loadedConfig2: LoadedRouterConfig = loadedConfig.routes[0]._loadedConfig;
|
||||
const module2: any = loadedConfig2.module;
|
||||
expect(loadedConfig2.routes[0].path).toEqual('LoadedModule2');
|
||||
expect(module2.parent).toBe(module);
|
||||
|
@ -165,12 +165,12 @@ describe('RouterPreloader', () => {
|
|||
|
||||
const c = router.config;
|
||||
|
||||
const loadedConfig: LoadedRouterConfig = (<any>c[0])._loadedConfig;
|
||||
const loadedConfig: LoadedRouterConfig = c[0]._loadedConfig;
|
||||
const module: any = loadedConfig.module;
|
||||
expect(module.parent).toBe(testModule);
|
||||
|
||||
const loadedConfig2: LoadedRouterConfig = (<any>loadedConfig.routes[0])._loadedConfig;
|
||||
const loadedConfig3: LoadedRouterConfig = (<any>loadedConfig2.routes[0])._loadedConfig;
|
||||
const loadedConfig2: LoadedRouterConfig = loadedConfig.routes[0]._loadedConfig;
|
||||
const loadedConfig3: LoadedRouterConfig = loadedConfig2.routes[0]._loadedConfig;
|
||||
const module3: any = loadedConfig3.module;
|
||||
expect(module3.parent).toBe(module2);
|
||||
})));
|
||||
|
@ -204,8 +204,8 @@ describe('RouterPreloader', () => {
|
|||
tick();
|
||||
|
||||
const c = router.config;
|
||||
expect(!!((<any>c[0])._loadedConfig)).toBe(false);
|
||||
expect(!!((<any>c[1])._loadedConfig)).toBe(true);
|
||||
expect(c[0]._loadedConfig).not.toBeDefined();
|
||||
expect(c[1]._loadedConfig).toBeDefined();
|
||||
})));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue