refactor(router): clean up naming
This commit is contained in:
@@ -7,16 +7,16 @@
|
||||
*/
|
||||
|
||||
|
||||
export {ExtraOptions, provideRoutes, provideRouterConfig} from './src/common_router_providers';
|
||||
export {Data, ResolveData, Route, RouterConfig} from './src/config';
|
||||
export {ExtraOptions, provideRouterConfig, provideRoutes} from './src/common_router_providers';
|
||||
export {Data, ResolveData, Route, RouterConfig, Routes} from './src/config';
|
||||
export {RouterLink, RouterLinkWithHref} from './src/directives/router_link';
|
||||
export {RouterLinkActive} from './src/directives/router_link_active';
|
||||
export {RouterOutlet} from './src/directives/router_outlet';
|
||||
export {CanActivate, CanDeactivate, Resolve} from './src/interfaces';
|
||||
export {Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router, RoutesRecognized} from './src/router';
|
||||
export {ROUTER_DIRECTIVES, RouterAppModule} from './src/router_app_module';
|
||||
export {RouterOutletMap} from './src/router_outlet_map';
|
||||
export {provideRouter} from './src/router_providers';
|
||||
export {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot} from './src/router_state';
|
||||
export {PRIMARY_OUTLET, Params} from './src/shared';
|
||||
export {RouterAppModule, ROUTER_DIRECTIVES} from './src/router_app_module';
|
||||
export {DefaultUrlSerializer, UrlPathWithParams, UrlSerializer, UrlTree} from './src/url_tree';
|
||||
|
||||
@@ -15,7 +15,7 @@ import {Observer} from 'rxjs/Observer';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {EmptyError} from 'rxjs/util/EmptyError';
|
||||
|
||||
import {Route, RouterConfig} from './config';
|
||||
import {Route, Routes} from './config';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
import {PRIMARY_OUTLET} from './shared';
|
||||
import {UrlPathWithParams, UrlSegment, UrlTree} from './url_tree';
|
||||
@@ -38,7 +38,7 @@ function absoluteRedirect(newPaths: UrlPathWithParams[]): Observable<UrlSegment>
|
||||
}
|
||||
|
||||
export function applyRedirects(
|
||||
configLoader: RouterConfigLoader, urlTree: UrlTree, config: RouterConfig): Observable<UrlTree> {
|
||||
configLoader: RouterConfigLoader, urlTree: UrlTree, config: Routes): Observable<UrlTree> {
|
||||
return expandSegment(configLoader, config, urlTree.root, PRIMARY_OUTLET)
|
||||
.map(rootSegment => createUrlTree(urlTree, rootSegment))
|
||||
.catch(e => {
|
||||
@@ -190,8 +190,8 @@ function matchPathsWithParamsAgainstRoute(
|
||||
function getChildConfig(configLoader: RouterConfigLoader, route: Route): Observable<Route[]> {
|
||||
if (route.children) {
|
||||
return of (route.children);
|
||||
} else if (route.mountChildren) {
|
||||
return configLoader.load(route.mountChildren).map(r => {
|
||||
} else if (route.loadChildren) {
|
||||
return configLoader.load(route.loadChildren).map(r => {
|
||||
(<any>route)._loadedConfig = r;
|
||||
return r.routes;
|
||||
});
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
|
||||
import {APP_INITIALIZER, AppModuleFactoryLoader, ApplicationRef, ComponentResolver, Injector, OpaqueToken, SystemJsAppModuleLoader} from '@angular/core';
|
||||
|
||||
import {RouterConfig} from './config';
|
||||
import {Routes} from './config';
|
||||
import {Router} from './router';
|
||||
import {ROUTER_CONFIG} from './router_config_loader';
|
||||
import {ROUTER_CONFIG, ROUTES} from './router_config_loader';
|
||||
import {RouterOutletMap} from './router_outlet_map';
|
||||
import {ActivatedRoute} from './router_state';
|
||||
import {DefaultUrlSerializer, UrlSerializer} from './url_tree';
|
||||
|
||||
export const ROUTER_OPTIONS = new OpaqueToken('ROUTER_OPTIONS');
|
||||
export const ROUTER_CONFIGURATION = new OpaqueToken('ROUTER_CONFIGURATION');
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
@@ -26,7 +26,7 @@ export interface ExtraOptions { enableTracing?: boolean; }
|
||||
export function setupRouter(
|
||||
ref: ApplicationRef, resolver: ComponentResolver, urlSerializer: UrlSerializer,
|
||||
outletMap: RouterOutletMap, location: Location, injector: Injector,
|
||||
loader: AppModuleFactoryLoader, config: RouterConfig, opts: ExtraOptions) {
|
||||
loader: AppModuleFactoryLoader, config: Routes, opts: ExtraOptions) {
|
||||
if (ref.componentTypes.length == 0) {
|
||||
throw new Error('Bootstrap at least one component before injecting Router.');
|
||||
}
|
||||
@@ -82,10 +82,12 @@ export function setupRouterInitializer(injector: Injector) {
|
||||
*
|
||||
* @deprecated use RouterAppModule instead
|
||||
*/
|
||||
export function provideRouter(_config: RouterConfig, _opts: ExtraOptions): any[] {
|
||||
export function provideRouter(routes: Routes, config: ExtraOptions): any[] {
|
||||
return [
|
||||
{provide: ROUTER_CONFIG, useValue: _config}, {provide: ROUTER_OPTIONS, useValue: _opts},
|
||||
Location, {provide: LocationStrategy, useClass: PathLocationStrategy},
|
||||
{provide: ROUTES, useExisting: ROUTER_CONFIG}, {provide: ROUTER_CONFIG, useValue: routes},
|
||||
|
||||
{provide: ROUTER_CONFIGURATION, useValue: config}, Location,
|
||||
{provide: LocationStrategy, useClass: PathLocationStrategy},
|
||||
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
|
||||
|
||||
{
|
||||
@@ -93,7 +95,7 @@ export function provideRouter(_config: RouterConfig, _opts: ExtraOptions): any[]
|
||||
useFactory: setupRouter,
|
||||
deps: [
|
||||
ApplicationRef, ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector,
|
||||
AppModuleFactoryLoader, ROUTER_CONFIG, ROUTER_OPTIONS
|
||||
AppModuleFactoryLoader, ROUTES, ROUTER_CONFIGURATION
|
||||
]
|
||||
},
|
||||
|
||||
@@ -122,8 +124,8 @@ export function provideRouter(_config: RouterConfig, _opts: ExtraOptions): any[]
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function provideRoutes(config: RouterConfig): any {
|
||||
return {provide: ROUTER_CONFIG, useValue: config};
|
||||
export function provideRoutes(routes: Routes): any {
|
||||
return {provide: ROUTES, useValue: routes};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,6 +144,6 @@ export function provideRoutes(config: RouterConfig): any {
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function provideRouterConfig(options: ExtraOptions): any {
|
||||
return {provide: ROUTER_OPTIONS, useValue: options};
|
||||
export function provideRouterConfig(config: ExtraOptions): any {
|
||||
return {provide: ROUTER_CONFIGURATION, useValue: config};
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -79,7 +79,7 @@ export class RouterOutlet {
|
||||
// const componentName = component ? component.name : null;
|
||||
// console.warn(
|
||||
// `'${componentName}' not found in precompile array. To ensure all components referred
|
||||
// to by the RouterConfig are compiled, you must add '${componentName}' to the
|
||||
// to by the Routes are compiled, you must add '${componentName}' to the
|
||||
// 'precompile' array of your application component. This will be required in a future
|
||||
// release of the router.`);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {Data, ResolveData, Route, RouterConfig} from './config';
|
||||
import {Data, ResolveData, Route, Routes} from './config';
|
||||
import {ActivatedRouteSnapshot, InheritedResolve, RouterStateSnapshot} from './router_state';
|
||||
import {PRIMARY_OUTLET, Params} from './shared';
|
||||
import {UrlPathWithParams, UrlSegment, UrlTree, mapChildrenIntoArray} from './url_tree';
|
||||
@@ -38,9 +38,8 @@ class InheritedFromParent {
|
||||
}
|
||||
}
|
||||
|
||||
export function recognize(
|
||||
rootComponentType: Type, config: RouterConfig, urlTree: UrlTree,
|
||||
url: string): Observable<RouterStateSnapshot> {
|
||||
export function recognize(rootComponentType: Type, config: Routes, urlTree: UrlTree, url: string):
|
||||
Observable<RouterStateSnapshot> {
|
||||
try {
|
||||
const children =
|
||||
processSegment(config, urlTree.root, InheritedFromParent.empty, PRIMARY_OUTLET);
|
||||
@@ -152,7 +151,7 @@ function processPathsWithParamsAgainstRoute(
|
||||
function getChildConfig(route: Route): Route[] {
|
||||
if (route.children) {
|
||||
return route.children;
|
||||
} else if (route.mountChildren) {
|
||||
} else if (route.loadChildren) {
|
||||
return (<any>route)._loadedConfig.routes;
|
||||
} else {
|
||||
return [];
|
||||
|
||||
@@ -22,7 +22,7 @@ import {Subscription} from 'rxjs/Subscription';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {applyRedirects} from './apply_redirects';
|
||||
import {ResolveData, RouterConfig, validateConfig} from './config';
|
||||
import {ResolveData, Routes, validateConfig} from './config';
|
||||
import {createRouterState} from './create_router_state';
|
||||
import {createUrlTree} from './create_url_tree';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
@@ -113,7 +113,7 @@ export type Event = NavigationStart | NavigationEnd | NavigationCancel | Navigat
|
||||
/**
|
||||
* The `Router` is responsible for mapping URLs to components.
|
||||
*
|
||||
* See {@link RouterConfig) for more details and examples.
|
||||
* See {@link Routes) for more details and examples.
|
||||
*
|
||||
* @stable
|
||||
*/
|
||||
@@ -123,7 +123,7 @@ export class Router {
|
||||
private locationSubscription: Subscription;
|
||||
private routerEvents: Subject<Event>;
|
||||
private navigationId: number = 0;
|
||||
private config: RouterConfig;
|
||||
private config: Routes;
|
||||
private futureUrlTree: UrlTree;
|
||||
private configLoader: RouterConfigLoader;
|
||||
|
||||
@@ -134,7 +134,7 @@ export class Router {
|
||||
private rootComponentType: Type, private resolver: ComponentResolver,
|
||||
private urlSerializer: UrlSerializer, private outletMap: RouterOutletMap,
|
||||
private location: Location, private injector: Injector, loader: AppModuleFactoryLoader,
|
||||
config: RouterConfig) {
|
||||
config: Routes) {
|
||||
this.resetConfig(config);
|
||||
this.routerEvents = new Subject<Event>();
|
||||
this.currentUrlTree = createEmptyUrlTree();
|
||||
@@ -180,7 +180,7 @@ export class Router {
|
||||
* ]);
|
||||
* ```
|
||||
*/
|
||||
resetConfig(config: RouterConfig): void {
|
||||
resetConfig(config: Routes): void {
|
||||
validateConfig(config);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@@ -6,20 +6,19 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AppModule} from '@angular/core';
|
||||
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
|
||||
import {APP_INITIALIZER, AppModuleFactoryLoader, ApplicationRef, ComponentResolver, Injector, OpaqueToken, SystemJsAppModuleLoader} from '@angular/core';
|
||||
import {AppModule, AppModuleFactoryLoader, ApplicationRef, ComponentResolver, Injector, OpaqueToken, SystemJsAppModuleLoader} from '@angular/core';
|
||||
|
||||
import {ROUTER_CONFIGURATION, setupRouter} from './common_router_providers';
|
||||
import {RouterLink, RouterLinkWithHref} from './directives/router_link';
|
||||
import {RouterLinkActive} from './directives/router_link_active';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
import {Router} from './router';
|
||||
import {setupRouter, ROUTER_OPTIONS} from './common_router_providers';
|
||||
import {ROUTER_CONFIG} from './router_config_loader';
|
||||
import {ROUTES} from './router_config_loader';
|
||||
import {RouterOutletMap} from './router_outlet_map';
|
||||
import {ActivatedRoute} from './router_state';
|
||||
import {DefaultUrlSerializer, UrlSerializer} from './url_tree';
|
||||
|
||||
import {RouterLink, RouterLinkWithHref} from './directives/router_link';
|
||||
import {RouterLinkActive} from './directives/router_link_active';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
|
||||
/**
|
||||
* @stable
|
||||
@@ -42,19 +41,18 @@ export const ROUTER_DIRECTIVES = [RouterOutlet, RouterLink, RouterLinkWithHref,
|
||||
directives: ROUTER_DIRECTIVES,
|
||||
providers: [
|
||||
Location, {provide: LocationStrategy, useClass: PathLocationStrategy},
|
||||
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
|
||||
{
|
||||
{provide: UrlSerializer, useClass: DefaultUrlSerializer}, {
|
||||
provide: Router,
|
||||
useFactory: setupRouter,
|
||||
deps: [
|
||||
ApplicationRef, ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector,
|
||||
AppModuleFactoryLoader, ROUTER_CONFIG, ROUTER_OPTIONS
|
||||
AppModuleFactoryLoader, ROUTES, ROUTER_CONFIGURATION
|
||||
]
|
||||
},
|
||||
RouterOutletMap,
|
||||
{provide: ActivatedRoute, useFactory: (r: Router) => r.routerState.root, deps: [Router]},
|
||||
{provide: AppModuleFactoryLoader, useClass: SystemJsAppModuleLoader},
|
||||
{provide: ROUTER_OPTIONS, useValue: {enableTracing: false}}
|
||||
{provide: ROUTER_CONFIGURATION, useValue: {enableTracing: false}}
|
||||
]
|
||||
})
|
||||
export class RouterAppModule {
|
||||
|
||||
@@ -12,7 +12,11 @@ import {fromPromise} from 'rxjs/observable/fromPromise';
|
||||
|
||||
import {Route} from './config';
|
||||
|
||||
/**
|
||||
* @deprecated use Routes
|
||||
*/
|
||||
export const ROUTER_CONFIG = new OpaqueToken('ROUTER_CONFIG');
|
||||
export const ROUTES = new OpaqueToken('ROUTES');
|
||||
|
||||
export class LoadedRouterConfig {
|
||||
constructor(public routes: Route[], public factoryResolver: ComponentFactoryResolver) {}
|
||||
@@ -24,7 +28,7 @@ export class RouterConfigLoader {
|
||||
load(path: string): Observable<LoadedRouterConfig> {
|
||||
return fromPromise(this.loader.load(path).then(r => {
|
||||
const ref = r.create();
|
||||
return new LoadedRouterConfig(ref.injector.get(ROUTER_CONFIG), ref.componentFactoryResolver);
|
||||
return new LoadedRouterConfig(ref.injector.get(ROUTES), ref.componentFactoryResolver);
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import {PlatformLocation} from '@angular/common';
|
||||
import {BrowserPlatformLocation} from '@angular/platform-browser';
|
||||
|
||||
import {ExtraOptions, provideRouter as provideRouter_} from './common_router_providers';
|
||||
import {RouterConfig} from './config';
|
||||
import {Routes} from './config';
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ import {RouterConfig} from './config';
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function provideRouter(config: RouterConfig, opts: ExtraOptions = {}): any[] {
|
||||
export function provideRouter(config: Routes, opts: ExtraOptions = {}): any[] {
|
||||
return [
|
||||
{provide: PlatformLocation, useClass: BrowserPlatformLocation}, ...provideRouter_(config, opts)
|
||||
];
|
||||
|
||||
@@ -2,7 +2,7 @@ import {Observable} from 'rxjs/Observable';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {applyRedirects} from '../src/apply_redirects';
|
||||
import {RouterConfig} from '../src/config';
|
||||
import {Routes} from '../src/config';
|
||||
import {LoadedRouterConfig} from '../src/router_config_loader';
|
||||
import {DefaultUrlSerializer, UrlSegment, UrlTree, equalPathsWithParams} from '../src/url_tree';
|
||||
|
||||
@@ -136,7 +136,7 @@ describe('applyRedirects', () => {
|
||||
const loadedConfig =
|
||||
new LoadedRouterConfig([{path: 'b', component: ComponentB}], <any>'stubFactoryResolver');
|
||||
const loader = {load: (p: any) => of (loadedConfig)};
|
||||
const config = [{path: 'a', component: ComponentA, mountChildren: 'children'}];
|
||||
const config = [{path: 'a', component: ComponentA, loadChildren: 'children'}];
|
||||
|
||||
applyRedirects(<any>loader, tree('a/b'), config).forEach(r => {
|
||||
compareTrees(r, tree('/a/b'));
|
||||
@@ -148,7 +148,7 @@ describe('applyRedirects', () => {
|
||||
const loader = {
|
||||
load: (p: any) => new Observable<any>((obs: any) => obs.error(new Error('Loading Error')))
|
||||
};
|
||||
const config = [{path: 'a', component: ComponentA, mountChildren: 'children'}];
|
||||
const config = [{path: 'a', component: ComponentA, loadChildren: 'children'}];
|
||||
|
||||
applyRedirects(<any>loader, tree('a/b'), config).subscribe(() => {}, (e) => {
|
||||
expect(e.message).toEqual('Loading Error');
|
||||
@@ -188,7 +188,7 @@ describe('applyRedirects', () => {
|
||||
});
|
||||
|
||||
it('should redirect empty path route only when terminal', () => {
|
||||
const config: RouterConfig = [
|
||||
const config: Routes = [
|
||||
{
|
||||
path: 'a',
|
||||
component: ComponentA,
|
||||
@@ -315,7 +315,7 @@ describe('applyRedirects', () => {
|
||||
});
|
||||
|
||||
it('should not create a new child (terminal)', () => {
|
||||
const config: RouterConfig = [{
|
||||
const config: Routes = [{
|
||||
path: 'a',
|
||||
children: [
|
||||
{path: 'b', component: ComponentB, children: [{path: 'd', component: ComponentB}]},
|
||||
@@ -338,7 +338,7 @@ describe('applyRedirects', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function checkRedirect(config: RouterConfig, url: string, callback: any): void {
|
||||
function checkRedirect(config: Routes, url: string, callback: any): void {
|
||||
applyRedirects(null, tree(url), config).subscribe(callback, e => { throw e; });
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,16 @@ describe('config', () => {
|
||||
`Invalid configuration of route 'a': redirectTo and children cannot be used together`);
|
||||
});
|
||||
|
||||
it('should throw when redirectTo and mountChildren are used together', () => {
|
||||
expect(() => { validateConfig([{path: 'a', redirectTo: 'b', mountChildren: 'value'}]); })
|
||||
it('should throw when redirectTo and loadChildren are used together', () => {
|
||||
expect(() => { validateConfig([{path: 'a', redirectTo: 'b', loadChildren: 'value'}]); })
|
||||
.toThrowError(
|
||||
`Invalid configuration of route 'a': redirectTo and mountChildren cannot be used together`);
|
||||
`Invalid configuration of route 'a': redirectTo and loadChildren cannot be used together`);
|
||||
});
|
||||
|
||||
it('should throw when children and mountChildren are used together', () => {
|
||||
expect(() => { validateConfig([{path: 'a', children: [], mountChildren: 'value'}]); })
|
||||
it('should throw when children and loadChildren are used together', () => {
|
||||
expect(() => { validateConfig([{path: 'a', children: [], loadChildren: 'value'}]); })
|
||||
.toThrowError(
|
||||
`Invalid configuration of route 'a': children and mountChildren cannot be used together`);
|
||||
`Invalid configuration of route 'a': children and loadChildren cannot be used together`);
|
||||
});
|
||||
|
||||
it('should throw when component and redirectTo are used together', () => {
|
||||
@@ -42,7 +42,7 @@ describe('config', () => {
|
||||
it('should throw when none of component and children or direct are missing', () => {
|
||||
expect(() => { validateConfig([{path: 'a'}]); })
|
||||
.toThrowError(
|
||||
`Invalid configuration of route 'a': component, redirectTo, children, mountChildren must be provided`);
|
||||
`Invalid configuration of route 'a': component, redirectTo, children, loadChildren must be provided`);
|
||||
});
|
||||
|
||||
it('should throw when path starts with a slash', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {RouterConfig} from '../src/config';
|
||||
import {Routes} from '../src/config';
|
||||
import {createRouterState} from '../src/create_router_state';
|
||||
import {recognize} from '../src/recognize';
|
||||
import {ActivatedRoute, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState} from '../src/router_state';
|
||||
@@ -84,7 +84,7 @@ function advanceNode(node: TreeNode<ActivatedRoute>): void {
|
||||
node.children.forEach(advanceNode);
|
||||
}
|
||||
|
||||
function createState(config: RouterConfig, url: string): RouterStateSnapshot {
|
||||
function createState(config: Routes, url: string): RouterStateSnapshot {
|
||||
let res: RouterStateSnapshot;
|
||||
recognize(RootComponent, config, tree(url), url).forEach(s => res = s);
|
||||
return res;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {RouterConfig} from '../src/config';
|
||||
import {Routes} from '../src/config';
|
||||
import {recognize} from '../src/recognize';
|
||||
import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state';
|
||||
import {PRIMARY_OUTLET, Params} from '../src/shared';
|
||||
@@ -529,7 +529,7 @@ describe('recognize', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function checkRecognize(config: RouterConfig, url: string, callback: any): void {
|
||||
function checkRecognize(config: Routes, url: string, callback: any): void {
|
||||
recognize(RootComponent, config, tree(url), url).subscribe(callback, e => { throw e; });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {RouterConfig} from '../src/config';
|
||||
import {Routes} from '../src/config';
|
||||
import {recognize} from '../src/recognize';
|
||||
import {resolve} from '../src/resolve';
|
||||
import {RouterStateSnapshot} from '../src/router_state';
|
||||
@@ -22,7 +22,7 @@ describe('resolve', () => {
|
||||
});
|
||||
|
||||
function checkResolve(
|
||||
config: RouterConfig, url: string, resolved: {[k: string]: string}, callback: any): void {
|
||||
config: Routes, url: string, resolved: {[k: string]: string}, callback: any): void {
|
||||
const resolver = {
|
||||
resolveComponent: (component: string): Promise<any> => {
|
||||
if (resolved[component]) {
|
||||
|
||||
@@ -11,13 +11,12 @@ import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, CanActivate, CanDeactivate, DefaultUrlSerializer, Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Params, ROUTER_DIRECTIVES, Resolve, Router, RouterConfig, RouterOutletMap, RouterStateSnapshot, RoutesRecognized, UrlSerializer, provideRoutes} from '../index';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, CanActivate, CanDeactivate, DefaultUrlSerializer, Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Params, ROUTER_DIRECTIVES, Resolve, Router, RouterOutletMap, RouterStateSnapshot, Routes, RoutesRecognized, UrlSerializer, provideRoutes} from '../index';
|
||||
|
||||
describe('Integration', () => {
|
||||
|
||||
beforeEachProviders(() => {
|
||||
let config: RouterConfig =
|
||||
[{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}];
|
||||
let config: Routes = [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}];
|
||||
|
||||
return [
|
||||
RouterOutletMap,
|
||||
@@ -1124,7 +1123,7 @@ describe('Integration', () => {
|
||||
|
||||
const fixture = createRoot(tcb, router, RootCmp);
|
||||
|
||||
router.resetConfig([{path: 'lazy', mountChildren: 'expected'}]);
|
||||
router.resetConfig([{path: 'lazy', loadChildren: 'expected'}]);
|
||||
|
||||
router.navigateByUrl('/lazy/loaded/child');
|
||||
advance(fixture);
|
||||
@@ -1142,7 +1141,7 @@ describe('Integration', () => {
|
||||
(<any>loader).expectedPath = 'expected';
|
||||
const fixture = createRoot(tcb, router, RootCmp);
|
||||
|
||||
router.resetConfig([{path: 'lazy', mountChildren: 'invalid'}]);
|
||||
router.resetConfig([{path: 'lazy', loadChildren: 'invalid'}]);
|
||||
|
||||
const recordedEvents: any = [];
|
||||
router.events.forEach(e => recordedEvents.push(e));
|
||||
|
||||
@@ -133,7 +133,7 @@ export const ROUTER_CONFIG = [
|
||||
{path: '', terminal: true, redirectTo: 'inbox'},
|
||||
{path: 'inbox', component: InboxCmp},
|
||||
{path: 'drafts', component: DraftsCmp},
|
||||
{path: 'detail', mountChildren: 'app/inbox-detail.js' }
|
||||
{path: 'detail', loadChildren: 'app/inbox-detail.js' }
|
||||
];
|
||||
|
||||
@Component({
|
||||
|
||||
+16
-5
@@ -91,10 +91,13 @@ export declare type Params = {
|
||||
export declare const PRIMARY_OUTLET: string;
|
||||
|
||||
/** @experimental */
|
||||
export declare function provideRouter(config: RouterConfig, opts?: ExtraOptions): any[];
|
||||
export declare function provideRouter(config: Routes, opts?: ExtraOptions): any[];
|
||||
|
||||
/** @experimental */
|
||||
export declare function provideRoutes(config: RouterConfig): any;
|
||||
export declare function provideRouterConfig(config: ExtraOptions): any;
|
||||
|
||||
/** @experimental */
|
||||
export declare function provideRoutes(routes: Routes): any;
|
||||
|
||||
/** @experimental */
|
||||
export interface Resolve<T> {
|
||||
@@ -117,19 +120,24 @@ export declare class Router {
|
||||
events: Observable<Event>;
|
||||
routerState: RouterState;
|
||||
url: string;
|
||||
constructor(rootComponentType: Type, resolver: ComponentResolver, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: AppModuleFactoryLoader, config: RouterConfig);
|
||||
constructor(rootComponentType: Type, resolver: ComponentResolver, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: AppModuleFactoryLoader, config: Routes);
|
||||
createUrlTree(commands: any[], {relativeTo, queryParams, fragment}?: NavigationExtras): UrlTree;
|
||||
navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
|
||||
navigateByUrl(url: string | UrlTree): Promise<boolean>;
|
||||
parseUrl(url: string): UrlTree;
|
||||
resetConfig(config: RouterConfig): void;
|
||||
resetConfig(config: Routes): void;
|
||||
serializeUrl(url: UrlTree): string;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare const ROUTER_DIRECTIVES: (typeof RouterOutlet | typeof RouterLink | typeof RouterLinkWithHref | typeof RouterLinkActive)[];
|
||||
|
||||
/** @stable */
|
||||
/** @experimental */
|
||||
export declare class RouterAppModule {
|
||||
constructor(injector: Injector);
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export declare type RouterConfig = Route[];
|
||||
|
||||
/** @stable */
|
||||
@@ -202,6 +210,9 @@ export declare class RouterStateSnapshot extends Tree<ActivatedRouteSnapshot> {
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare type Routes = Route[];
|
||||
|
||||
/** @stable */
|
||||
export declare class RoutesRecognized {
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user