fix(router): expose initalNavigation and dispose so they can be used with webworkers
This commit is contained in:
parent
e1109d52e1
commit
b77a4a40a4
|
@ -47,7 +47,8 @@ export function recognize(rootComponentType: Type, config: Routes, urlTree: UrlT
|
|||
[], Object.freeze({}), {}, PRIMARY_OUTLET, rootComponentType, null, urlTree.root, -1,
|
||||
InheritedResolve.empty);
|
||||
const rootNode = new TreeNode<ActivatedRouteSnapshot>(root, children);
|
||||
return of (new RouterStateSnapshot(url, rootNode, Object.freeze(urlTree.queryParams), urlTree.fragment));
|
||||
return of (new RouterStateSnapshot(
|
||||
url, rootNode, Object.freeze(urlTree.queryParams), urlTree.fragment));
|
||||
} catch (e) {
|
||||
if (e instanceof NoMatch) {
|
||||
return new Observable<RouterStateSnapshot>(
|
||||
|
@ -113,9 +114,9 @@ function processPathsWithParamsAgainstRoute(
|
|||
if (route.path === '**') {
|
||||
const params = paths.length > 0 ? last(paths).parameters : {};
|
||||
const snapshot = new ActivatedRouteSnapshot(
|
||||
paths, Object.freeze(merge(inherited.allParams, params)), merge(inherited.allData, getData(route)), outlet,
|
||||
route.component, route, getSourceSegment(rawSegment), getPathIndexShift(rawSegment) - 1,
|
||||
newInheritedResolve);
|
||||
paths, Object.freeze(merge(inherited.allParams, params)),
|
||||
merge(inherited.allData, getData(route)), outlet, route.component, route,
|
||||
getSourceSegment(rawSegment), getPathIndexShift(rawSegment) - 1, newInheritedResolve);
|
||||
return [new TreeNode<ActivatedRouteSnapshot>(snapshot, [])];
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ export class Router {
|
|||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Sets up the location change listener and performs the inital navigation
|
||||
*/
|
||||
initialNavigation(): void {
|
||||
this.setUpLocationChangeListener();
|
||||
|
@ -185,7 +185,7 @@ export class Router {
|
|||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Disposes of the router.
|
||||
*/
|
||||
dispose(): void { this.locationSubscription.unsubscribe(); }
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ describe('recognize', () => {
|
|||
checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, '', {}, RootComponent);
|
||||
const child = s.firstChild(s.root);
|
||||
expect(() => child.params['prop'] = "new").toThrowError(/Can't add property/);
|
||||
expect(() => child.params['prop'] = 'new').toThrowError(/Can't add property/);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -515,7 +515,7 @@ describe('recognize', () => {
|
|||
|
||||
it('should freeze query params object', () => {
|
||||
checkRecognize([{path: 'a', component: ComponentA}], 'a?q=11', (s: RouterStateSnapshot) => {
|
||||
expect(() => s.queryParams['prop'] = "new").toThrowError(/Can't add property/);
|
||||
expect(() => s.queryParams['prop'] = 'new').toThrowError(/Can't add property/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<nav>
|
||||
<ul>
|
||||
<li class="start" [routerLink]="['/Start']">Start</li>
|
||||
<li class="about" [routerLink]="['/About']">About</li>
|
||||
<li class="contact" [routerLink]="['/Contact']">Contact</li>
|
||||
<li class="start" routerLink="/">Start</li>
|
||||
<li class="about" routerLink="/about">About</li>
|
||||
<li class="contact" routerLink="/contact">Contact</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<main>
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ROUTER_PROVIDERS} from '@angular/router-deprecated';
|
||||
import {provideRouter} from '@angular/router';
|
||||
import {WORKER_APP_LOCATION_PROVIDERS} from '@angular/platform-browser';
|
||||
import {bootstrapWorkerApp} from '@angular/platform-browser-dynamic';
|
||||
|
||||
import {HashLocationStrategy, LocationStrategy} from '@angular/common';
|
||||
import {App} from './index_common';
|
||||
import {App, ROUTES} from './index_common';
|
||||
|
||||
export function main() {
|
||||
bootstrapWorkerApp(App, [
|
||||
ROUTER_PROVIDERS,
|
||||
provideRouter(ROUTES),
|
||||
WORKER_APP_LOCATION_PROVIDERS,
|
||||
{provide: LocationStrategy, useClass: HashLocationStrategy}
|
||||
]);
|
||||
|
|
|
@ -10,13 +10,18 @@ import {Component} from '@angular/core';
|
|||
import {Start} from './components/start';
|
||||
import {About} from './components/about';
|
||||
import {Contact} from './components/contact';
|
||||
import {ROUTER_DIRECTIVES, RouteConfig, Route} from '@angular/router-deprecated';
|
||||
import {ROUTER_DIRECTIVES, Router} from '@angular/router';
|
||||
|
||||
@Component({selector: 'app', directives: [ROUTER_DIRECTIVES], templateUrl: 'app.html'})
|
||||
@RouteConfig([
|
||||
new Route({path: '/', component: Start, name: "Start"}),
|
||||
new Route({path: '/contact', component: Contact, name: "Contact"}),
|
||||
new Route({path: '/about', component: About, name: "About"})
|
||||
])
|
||||
export class App {
|
||||
constructor(router: Router) {
|
||||
// this should not be required once web worker bootstrap method can use modules
|
||||
router.initialNavigation();
|
||||
}
|
||||
}
|
||||
|
||||
export const ROUTES = [
|
||||
{path: '', component: Start},
|
||||
{path: 'contact', component: Contact},
|
||||
{path: 'about', component: About}
|
||||
];
|
|
@ -16,7 +16,7 @@ System.config({
|
|||
'@angular/common': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/platform-browser': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/platform-browser-dynamic': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/router-deprecated': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/router': {main: 'index.js', defaultExtension: 'js'},
|
||||
'rxjs': {
|
||||
defaultExtension: 'js'
|
||||
},
|
||||
|
|
|
@ -127,6 +127,8 @@ export declare class Router {
|
|||
url: string;
|
||||
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;
|
||||
dispose(): void;
|
||||
initialNavigation(): void;
|
||||
navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
|
||||
navigateByUrl(url: string | UrlTree): Promise<boolean>;
|
||||
parseUrl(url: string): UrlTree;
|
||||
|
|
Loading…
Reference in New Issue