1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { LocationStrategy, Location, PlatformLocation, APP_BASE_HREF, ViewportScroller, HashLocationStrategy, PathLocationStrategy, LOCATION_INITIALIZED } from '@angular/common';
|
8 | import { Component, ɵisObservable, ɵisPromise, NgModuleRef, InjectionToken, NgModuleFactory, ɵConsole, NgZone, isDevMode, Directive, Attribute, Renderer2, ElementRef, Input, HostListener, HostBinding, Optional, ContentChildren, EventEmitter, ViewContainerRef, ComponentFactoryResolver, ChangeDetectorRef, Output, Injectable, NgModuleFactoryLoader, Compiler, Injector, ApplicationRef, SystemJsNgModuleLoader, NgProbeToken, ANALYZE_FOR_ENTRY_COMPONENTS, SkipSelf, Inject, APP_INITIALIZER, APP_BOOTSTRAP_LISTENER, NgModule, Version } from '@angular/core';
|
9 | import { of, from, BehaviorSubject, EmptyError, Observable, combineLatest, defer, Subject, EMPTY } from 'rxjs';
|
10 | import { map, concatAll, last as last$1, catchError, first, mergeMap, every, switchMap, take, startWith, scan, filter, concatMap, reduce, tap, finalize, mergeAll } from 'rxjs/operators';
|
11 | import { ɵgetDOM } from '@angular/platform-browser';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | class RouterEvent {
|
46 | |
47 |
|
48 |
|
49 |
|
50 | constructor(id, url) {
|
51 | this.id = id;
|
52 | this.url = url;
|
53 | }
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | class NavigationStart extends RouterEvent {
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | constructor(
|
68 | /** @docsNotRequired */
|
69 | id,
|
70 | /** @docsNotRequired */
|
71 | url,
|
72 | /** @docsNotRequired */
|
73 | navigationTrigger = 'imperative',
|
74 | /** @docsNotRequired */
|
75 | restoredState = null) {
|
76 | super(id, url);
|
77 | this.navigationTrigger = navigationTrigger;
|
78 | this.restoredState = restoredState;
|
79 | }
|
80 | |
81 |
|
82 |
|
83 |
|
84 | toString() { return `NavigationStart(id: ${this.id}, url: '${this.url}')`; }
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | class NavigationEnd extends RouterEvent {
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 | constructor(
|
98 | /** @docsNotRequired */
|
99 | id,
|
100 | /** @docsNotRequired */
|
101 | url, urlAfterRedirects) {
|
102 | super(id, url);
|
103 | this.urlAfterRedirects = urlAfterRedirects;
|
104 | }
|
105 | |
106 |
|
107 |
|
108 |
|
109 | toString() {
|
110 | return `NavigationEnd(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}')`;
|
111 | }
|
112 | }
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | class NavigationCancel extends RouterEvent {
|
119 | |
120 |
|
121 |
|
122 |
|
123 |
|
124 | constructor(
|
125 | /** @docsNotRequired */
|
126 | id,
|
127 | /** @docsNotRequired */
|
128 | url, reason) {
|
129 | super(id, url);
|
130 | this.reason = reason;
|
131 | }
|
132 | |
133 |
|
134 |
|
135 |
|
136 | toString() { return `NavigationCancel(id: ${this.id}, url: '${this.url}')`; }
|
137 | }
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | class NavigationError extends RouterEvent {
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 | constructor(
|
150 | /** @docsNotRequired */
|
151 | id,
|
152 | /** @docsNotRequired */
|
153 | url, error) {
|
154 | super(id, url);
|
155 | this.error = error;
|
156 | }
|
157 | |
158 |
|
159 |
|
160 |
|
161 | toString() {
|
162 | return `NavigationError(id: ${this.id}, url: '${this.url}', error: ${this.error})`;
|
163 | }
|
164 | }
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | class RoutesRecognized extends RouterEvent {
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | constructor(
|
178 | /** @docsNotRequired */
|
179 | id,
|
180 | /** @docsNotRequired */
|
181 | url, urlAfterRedirects, state) {
|
182 | super(id, url);
|
183 | this.urlAfterRedirects = urlAfterRedirects;
|
184 | this.state = state;
|
185 | }
|
186 | |
187 |
|
188 |
|
189 |
|
190 | toString() {
|
191 | return `RoutesRecognized(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}', state: ${this.state})`;
|
192 | }
|
193 | }
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 | class GuardsCheckStart extends RouterEvent {
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | constructor(
|
207 | /** @docsNotRequired */
|
208 | id,
|
209 | /** @docsNotRequired */
|
210 | url, urlAfterRedirects, state) {
|
211 | super(id, url);
|
212 | this.urlAfterRedirects = urlAfterRedirects;
|
213 | this.state = state;
|
214 | }
|
215 | |
216 |
|
217 |
|
218 | toString() {
|
219 | return `GuardsCheckStart(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}', state: ${this.state})`;
|
220 | }
|
221 | }
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | class GuardsCheckEnd extends RouterEvent {
|
228 | |
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | constructor(
|
236 | /** @docsNotRequired */
|
237 | id,
|
238 | /** @docsNotRequired */
|
239 | url, urlAfterRedirects, state, shouldActivate) {
|
240 | super(id, url);
|
241 | this.urlAfterRedirects = urlAfterRedirects;
|
242 | this.state = state;
|
243 | this.shouldActivate = shouldActivate;
|
244 | }
|
245 | |
246 |
|
247 |
|
248 | toString() {
|
249 | return `GuardsCheckEnd(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}', state: ${this.state}, shouldActivate: ${this.shouldActivate})`;
|
250 | }
|
251 | }
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | class ResolveStart extends RouterEvent {
|
261 | |
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 | constructor(
|
268 | /** @docsNotRequired */
|
269 | id,
|
270 | /** @docsNotRequired */
|
271 | url, urlAfterRedirects, state) {
|
272 | super(id, url);
|
273 | this.urlAfterRedirects = urlAfterRedirects;
|
274 | this.state = state;
|
275 | }
|
276 | |
277 |
|
278 |
|
279 | toString() {
|
280 | return `ResolveStart(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}', state: ${this.state})`;
|
281 | }
|
282 | }
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | class ResolveEnd extends RouterEvent {
|
290 | |
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | constructor(
|
297 | /** @docsNotRequired */
|
298 | id,
|
299 | /** @docsNotRequired */
|
300 | url, urlAfterRedirects, state) {
|
301 | super(id, url);
|
302 | this.urlAfterRedirects = urlAfterRedirects;
|
303 | this.state = state;
|
304 | }
|
305 | |
306 |
|
307 |
|
308 | toString() {
|
309 | return `ResolveEnd(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}', state: ${this.state})`;
|
310 | }
|
311 | }
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | class RouteConfigLoadStart {
|
318 | |
319 |
|
320 |
|
321 | constructor(route) {
|
322 | this.route = route;
|
323 | }
|
324 | |
325 |
|
326 |
|
327 | toString() { return `RouteConfigLoadStart(path: ${this.route.path})`; }
|
328 | }
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | class RouteConfigLoadEnd {
|
335 | |
336 |
|
337 |
|
338 | constructor(route) {
|
339 | this.route = route;
|
340 | }
|
341 | |
342 |
|
343 |
|
344 | toString() { return `RouteConfigLoadEnd(path: ${this.route.path})`; }
|
345 | }
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | class ChildActivationStart {
|
355 | |
356 |
|
357 |
|
358 | constructor(snapshot) {
|
359 | this.snapshot = snapshot;
|
360 | }
|
361 | |
362 |
|
363 |
|
364 | toString() {
|
365 |
|
366 | const path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
|
367 | return `ChildActivationStart(path: '${path}')`;
|
368 | }
|
369 | }
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 | class ChildActivationEnd {
|
378 | |
379 |
|
380 |
|
381 | constructor(snapshot) {
|
382 | this.snapshot = snapshot;
|
383 | }
|
384 | |
385 |
|
386 |
|
387 | toString() {
|
388 |
|
389 | const path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
|
390 | return `ChildActivationEnd(path: '${path}')`;
|
391 | }
|
392 | }
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 | class ActivationStart {
|
402 | |
403 |
|
404 |
|
405 | constructor(snapshot) {
|
406 | this.snapshot = snapshot;
|
407 | }
|
408 | |
409 |
|
410 |
|
411 | toString() {
|
412 |
|
413 | const path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
|
414 | return `ActivationStart(path: '${path}')`;
|
415 | }
|
416 | }
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 | class ActivationEnd {
|
426 | |
427 |
|
428 |
|
429 | constructor(snapshot) {
|
430 | this.snapshot = snapshot;
|
431 | }
|
432 | |
433 |
|
434 |
|
435 | toString() {
|
436 |
|
437 | const path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
|
438 | return `ActivationEnd(path: '${path}')`;
|
439 | }
|
440 | }
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 | class Scroll {
|
447 | |
448 |
|
449 |
|
450 |
|
451 |
|
452 | constructor(routerEvent, position, anchor) {
|
453 | this.routerEvent = routerEvent;
|
454 | this.position = position;
|
455 | this.anchor = anchor;
|
456 | }
|
457 | |
458 |
|
459 |
|
460 | toString() {
|
461 |
|
462 | const pos = this.position ? `${this.position[0]}, ${this.position[1]}` : null;
|
463 | return `Scroll(anchor: '${this.anchor}', position: '${pos}')`;
|
464 | }
|
465 | }
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 | class ɵEmptyOutletComponent {
|
481 | }
|
482 | ɵEmptyOutletComponent.decorators = [
|
483 | { type: Component, args: [{ template: `<router-outlet></router-outlet>` }] }
|
484 | ];
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 | const PRIMARY_OUTLET = 'primary';
|
504 | class ParamsAsMap {
|
505 | |
506 |
|
507 |
|
508 | constructor(params) { this.params = params || {}; }
|
509 | |
510 |
|
511 |
|
512 |
|
513 | has(name) { return this.params.hasOwnProperty(name); }
|
514 | |
515 |
|
516 |
|
517 |
|
518 | get(name) {
|
519 | if (this.has(name)) {
|
520 |
|
521 | const v = this.params[name];
|
522 | return Array.isArray(v) ? v[0] : v;
|
523 | }
|
524 | return null;
|
525 | }
|
526 | |
527 |
|
528 |
|
529 |
|
530 | getAll(name) {
|
531 | if (this.has(name)) {
|
532 |
|
533 | const v = this.params[name];
|
534 | return Array.isArray(v) ? v : [v];
|
535 | }
|
536 | return [];
|
537 | }
|
538 | |
539 |
|
540 |
|
541 | get keys() { return Object.keys(this.params); }
|
542 | }
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 | function convertToParamMap(params) {
|
551 | return new ParamsAsMap(params);
|
552 | }
|
553 |
|
554 | const NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError';
|
555 |
|
556 |
|
557 |
|
558 |
|
559 | function navigationCancelingError(message) {
|
560 |
|
561 | const error = Error('NavigationCancelingError: ' + message);
|
562 | (( (error)))[NAVIGATION_CANCELING_ERROR] = true;
|
563 | return error;
|
564 | }
|
565 |
|
566 |
|
567 |
|
568 |
|
569 | function isNavigationCancelingError(error) {
|
570 | return error && (( (error)))[NAVIGATION_CANCELING_ERROR];
|
571 | }
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 | function defaultUrlMatcher(segments, segmentGroup, route) {
|
580 |
|
581 | const parts = ( (route.path)).split('/');
|
582 | if (parts.length > segments.length) {
|
583 |
|
584 | return null;
|
585 | }
|
586 | if (route.pathMatch === 'full' &&
|
587 | (segmentGroup.hasChildren() || parts.length < segments.length)) {
|
588 |
|
589 | return null;
|
590 | }
|
591 |
|
592 | const posParams = {};
|
593 |
|
594 | for (let index = 0; index < parts.length; index++) {
|
595 |
|
596 | const part = parts[index];
|
597 |
|
598 | const segment = segments[index];
|
599 |
|
600 | const isParameter = part.startsWith(':');
|
601 | if (isParameter) {
|
602 | posParams[part.substring(1)] = segment;
|
603 | }
|
604 | else if (part !== segment.path) {
|
605 |
|
606 | return null;
|
607 | }
|
608 | }
|
609 | return { consumed: segments.slice(0, parts.length), posParams };
|
610 | }
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 | class LoadedRouterConfig {
|
617 | |
618 |
|
619 |
|
620 |
|
621 | constructor(routes, module) {
|
622 | this.routes = routes;
|
623 | this.module = module;
|
624 | }
|
625 | }
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 | function validateConfig(config, parentPath = '') {
|
632 |
|
633 | for (let i = 0; i < config.length; i++) {
|
634 |
|
635 | const route = config[i];
|
636 |
|
637 | const fullPath = getFullPath(parentPath, route);
|
638 | validateNode(route, fullPath);
|
639 | }
|
640 | }
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 | function validateNode(route, fullPath) {
|
647 | if (!route) {
|
648 | throw new Error(`
|
649 | Invalid configuration of route '${fullPath}': Encountered undefined route.
|
650 | The reason might be an extra comma.
|
651 |
|
652 | Example:
|
653 | const routes: Routes = [
|
654 | { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
|
655 | { path: 'dashboard', component: DashboardComponent },, << two commas
|
656 | { path: 'detail/:id', component: HeroDetailComponent }
|
657 | ];
|
658 | `);
|
659 | }
|
660 | if (Array.isArray(route)) {
|
661 | throw new Error(`Invalid configuration of route '${fullPath}': Array cannot be specified`);
|
662 | }
|
663 | if (!route.component && !route.children && !route.loadChildren &&
|
664 | (route.outlet && route.outlet !== PRIMARY_OUTLET)) {
|
665 | throw new Error(`Invalid configuration of route '${fullPath}': a componentless route without children or loadChildren cannot have a named outlet set`);
|
666 | }
|
667 | if (route.redirectTo && route.children) {
|
668 | throw new Error(`Invalid configuration of route '${fullPath}': redirectTo and children cannot be used together`);
|
669 | }
|
670 | if (route.redirectTo && route.loadChildren) {
|
671 | throw new Error(`Invalid configuration of route '${fullPath}': redirectTo and loadChildren cannot be used together`);
|
672 | }
|
673 | if (route.children && route.loadChildren) {
|
674 | throw new Error(`Invalid configuration of route '${fullPath}': children and loadChildren cannot be used together`);
|
675 | }
|
676 | if (route.redirectTo && route.component) {
|
677 | throw new Error(`Invalid configuration of route '${fullPath}': redirectTo and component cannot be used together`);
|
678 | }
|
679 | if (route.path && route.matcher) {
|
680 | throw new Error(`Invalid configuration of route '${fullPath}': path and matcher cannot be used together`);
|
681 | }
|
682 | if (route.redirectTo === void 0 && !route.component && !route.children && !route.loadChildren) {
|
683 | throw new Error(`Invalid configuration of route '${fullPath}'. One of the following must be provided: component, redirectTo, children or loadChildren`);
|
684 | }
|
685 | if (route.path === void 0 && route.matcher === void 0) {
|
686 | throw new Error(`Invalid configuration of route '${fullPath}': routes must have either a path or a matcher specified`);
|
687 | }
|
688 | if (typeof route.path === 'string' && route.path.charAt(0) === '/') {
|
689 | throw new Error(`Invalid configuration of route '${fullPath}': path cannot start with a slash`);
|
690 | }
|
691 | if (route.path === '' && route.redirectTo !== void 0 && route.pathMatch === void 0) {
|
692 |
|
693 | const exp = `The default value of 'pathMatch' is 'prefix', but often the intent is to use 'full'.`;
|
694 | throw new Error(`Invalid configuration of route '{path: "${fullPath}", redirectTo: "${route.redirectTo}"}': please provide 'pathMatch'. ${exp}`);
|
695 | }
|
696 | if (route.pathMatch !== void 0 && route.pathMatch !== 'full' && route.pathMatch !== 'prefix') {
|
697 | throw new Error(`Invalid configuration of route '${fullPath}': pathMatch can only be set to 'prefix' or 'full'`);
|
698 | }
|
699 | if (route.children) {
|
700 | validateConfig(route.children, fullPath);
|
701 | }
|
702 | }
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 | function getFullPath(parentPath, currentRoute) {
|
709 | if (!currentRoute) {
|
710 | return parentPath;
|
711 | }
|
712 | if (!parentPath && !currentRoute.path) {
|
713 | return '';
|
714 | }
|
715 | else if (parentPath && !currentRoute.path) {
|
716 | return `${parentPath}/`;
|
717 | }
|
718 | else if (!parentPath && currentRoute.path) {
|
719 | return currentRoute.path;
|
720 | }
|
721 | else {
|
722 | return `${parentPath}/${currentRoute.path}`;
|
723 | }
|
724 | }
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 | function standardizeConfig(r) {
|
731 |
|
732 | const children = r.children && r.children.map(standardizeConfig);
|
733 |
|
734 | const c = children ? Object.assign({}, r, { children }) : Object.assign({}, r);
|
735 | if (!c.component && (children || c.loadChildren) && (c.outlet && c.outlet !== PRIMARY_OUTLET)) {
|
736 | c.component = ɵEmptyOutletComponent;
|
737 | }
|
738 | return c;
|
739 | }
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 | function shallowEqualArrays(a, b) {
|
751 | if (a.length !== b.length)
|
752 | return false;
|
753 | for (let i = 0; i < a.length; ++i) {
|
754 | if (!shallowEqual(a[i], b[i]))
|
755 | return false;
|
756 | }
|
757 | return true;
|
758 | }
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 | function shallowEqual(a, b) {
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 | const k1 = ( (Object.keys(a)));
|
771 |
|
772 | const k2 = ( (Object.keys(b)));
|
773 | if (!k1 || !k2 || k1.length != k2.length) {
|
774 | return false;
|
775 | }
|
776 |
|
777 | let key;
|
778 | for (let i = 0; i < k1.length; i++) {
|
779 | key = k1[i];
|
780 | if (a[key] !== b[key]) {
|
781 | return false;
|
782 | }
|
783 | }
|
784 | return true;
|
785 | }
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 | function flatten(arr) {
|
793 | return Array.prototype.concat.apply([], arr);
|
794 | }
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 | function last(a) {
|
802 | return a.length > 0 ? a[a.length - 1] : null;
|
803 | }
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 | function forEach(map, callback) {
|
811 | for (const prop in map) {
|
812 | if (map.hasOwnProperty(prop)) {
|
813 | callback(map[prop], prop);
|
814 | }
|
815 | }
|
816 | }
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 | function waitForMap(obj, fn) {
|
824 | if (Object.keys(obj).length === 0) {
|
825 | return of({});
|
826 | }
|
827 |
|
828 | const waitHead = [];
|
829 |
|
830 | const waitTail = [];
|
831 |
|
832 | const res = {};
|
833 | forEach(obj, ( |
834 |
|
835 |
|
836 |
|
837 |
|
838 | (a, k) => {
|
839 |
|
840 | const mapped = fn(k, a).pipe(map(( |
841 |
|
842 |
|
843 |
|
844 | (r) => res[k] = r)));
|
845 | if (k === PRIMARY_OUTLET) {
|
846 | waitHead.push(mapped);
|
847 | }
|
848 | else {
|
849 | waitTail.push(mapped);
|
850 | }
|
851 | }));
|
852 |
|
853 | return of.apply(null, waitHead.concat(waitTail)).pipe(concatAll(), last$1(), map(( |
854 |
|
855 |
|
856 | () => res)));
|
857 | }
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 | function wrapIntoObservable(value) {
|
864 | if (ɵisObservable(value)) {
|
865 | return value;
|
866 | }
|
867 | if (ɵisPromise(value)) {
|
868 |
|
869 |
|
870 |
|
871 | return from(Promise.resolve(value));
|
872 | }
|
873 | return of(value);
|
874 | }
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 | function createEmptyUrlTree() {
|
884 | return new UrlTree(new UrlSegmentGroup([], {}), {}, null);
|
885 | }
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 | function containsTree(container, containee, exact) {
|
893 | if (exact) {
|
894 | return equalQueryParams(container.queryParams, containee.queryParams) &&
|
895 | equalSegmentGroups(container.root, containee.root);
|
896 | }
|
897 | return containsQueryParams(container.queryParams, containee.queryParams) &&
|
898 | containsSegmentGroup(container.root, containee.root);
|
899 | }
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 | function equalQueryParams(container, containee) {
|
906 |
|
907 | return shallowEqual(container, containee);
|
908 | }
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 | function equalSegmentGroups(container, containee) {
|
915 | if (!equalPath(container.segments, containee.segments))
|
916 | return false;
|
917 | if (container.numberOfChildren !== containee.numberOfChildren)
|
918 | return false;
|
919 | for (const c in containee.children) {
|
920 | if (!container.children[c])
|
921 | return false;
|
922 | if (!equalSegmentGroups(container.children[c], containee.children[c]))
|
923 | return false;
|
924 | }
|
925 | return true;
|
926 | }
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 | function containsQueryParams(container, containee) {
|
933 |
|
934 | return Object.keys(containee).length <= Object.keys(container).length &&
|
935 | Object.keys(containee).every(( |
936 |
|
937 |
|
938 |
|
939 | key => containee[key] === container[key]));
|
940 | }
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 | function containsSegmentGroup(container, containee) {
|
947 | return containsSegmentGroupHelper(container, containee, containee.segments);
|
948 | }
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 | function containsSegmentGroupHelper(container, containee, containeePaths) {
|
956 | if (container.segments.length > containeePaths.length) {
|
957 |
|
958 | const current = container.segments.slice(0, containeePaths.length);
|
959 | if (!equalPath(current, containeePaths))
|
960 | return false;
|
961 | if (containee.hasChildren())
|
962 | return false;
|
963 | return true;
|
964 | }
|
965 | else if (container.segments.length === containeePaths.length) {
|
966 | if (!equalPath(container.segments, containeePaths))
|
967 | return false;
|
968 | for (const c in containee.children) {
|
969 | if (!container.children[c])
|
970 | return false;
|
971 | if (!containsSegmentGroup(container.children[c], containee.children[c]))
|
972 | return false;
|
973 | }
|
974 | return true;
|
975 | }
|
976 | else {
|
977 |
|
978 | const current = containeePaths.slice(0, container.segments.length);
|
979 |
|
980 | const next = containeePaths.slice(container.segments.length);
|
981 | if (!equalPath(container.segments, current))
|
982 | return false;
|
983 | if (!container.children[PRIMARY_OUTLET])
|
984 | return false;
|
985 | return containsSegmentGroupHelper(container.children[PRIMARY_OUTLET], containee, next);
|
986 | }
|
987 | }
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 | class UrlTree {
|
1019 | |
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 | constructor(root, queryParams, fragment) {
|
1026 | this.root = root;
|
1027 | this.queryParams = queryParams;
|
1028 | this.fragment = fragment;
|
1029 | }
|
1030 | |
1031 |
|
1032 |
|
1033 | get queryParamMap() {
|
1034 | if (!this._queryParamMap) {
|
1035 | this._queryParamMap = convertToParamMap(this.queryParams);
|
1036 | }
|
1037 | return this._queryParamMap;
|
1038 | }
|
1039 | |
1040 |
|
1041 |
|
1042 |
|
1043 | toString() { return DEFAULT_SERIALIZER.serialize(this); }
|
1044 | }
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 | class UrlSegmentGroup {
|
1055 | |
1056 |
|
1057 |
|
1058 |
|
1059 | constructor(segments, children) {
|
1060 | this.segments = segments;
|
1061 | this.children = children;
|
1062 | |
1063 |
|
1064 |
|
1065 | this.parent = null;
|
1066 | forEach(children, ( |
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 | (v, k) => v.parent = this));
|
1074 | }
|
1075 | |
1076 |
|
1077 |
|
1078 |
|
1079 | hasChildren() { return this.numberOfChildren > 0; }
|
1080 | |
1081 |
|
1082 |
|
1083 |
|
1084 | get numberOfChildren() { return Object.keys(this.children).length; }
|
1085 | |
1086 |
|
1087 |
|
1088 |
|
1089 | toString() { return serializePaths(this); }
|
1090 | }
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 | class UrlSegment {
|
1118 | |
1119 |
|
1120 |
|
1121 |
|
1122 | constructor(path, parameters) {
|
1123 | this.path = path;
|
1124 | this.parameters = parameters;
|
1125 | }
|
1126 | |
1127 |
|
1128 |
|
1129 | get parameterMap() {
|
1130 | if (!this._parameterMap) {
|
1131 | this._parameterMap = convertToParamMap(this.parameters);
|
1132 | }
|
1133 | return this._parameterMap;
|
1134 | }
|
1135 | |
1136 |
|
1137 |
|
1138 |
|
1139 | toString() { return serializePath(this); }
|
1140 | }
|
1141 |
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 | function equalSegments(as, bs) {
|
1147 | return equalPath(as, bs) && as.every(( |
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 | (a, i) => shallowEqual(a.parameters, bs[i].parameters)));
|
1153 | }
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 | function equalPath(as, bs) {
|
1160 | if (as.length !== bs.length)
|
1161 | return false;
|
1162 | return as.every(( |
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 | (a, i) => a.path === bs[i].path));
|
1168 | }
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 | function mapChildrenIntoArray(segment, fn) {
|
1176 |
|
1177 | let res = [];
|
1178 | forEach(segment.children, ( |
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 | (child, childOutlet) => {
|
1184 | if (childOutlet === PRIMARY_OUTLET) {
|
1185 | res = res.concat(fn(child, childOutlet));
|
1186 | }
|
1187 | }));
|
1188 | forEach(segment.children, ( |
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 | (child, childOutlet) => {
|
1194 | if (childOutlet !== PRIMARY_OUTLET) {
|
1195 | res = res.concat(fn(child, childOutlet));
|
1196 | }
|
1197 | }));
|
1198 | return res;
|
1199 | }
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 | class UrlSerializer {
|
1214 | }
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 | class DefaultUrlSerializer {
|
1234 | |
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 | parse(url) {
|
1240 |
|
1241 | const p = new UrlParser(url);
|
1242 | return new UrlTree(p.parseRootSegment(), p.parseQueryParams(), p.parseFragment());
|
1243 | }
|
1244 | |
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 | serialize(tree) {
|
1250 |
|
1251 | const segment = `/${serializeSegment(tree.root, true)}`;
|
1252 |
|
1253 | const query = serializeQueryParams(tree.queryParams);
|
1254 |
|
1255 | const fragment = typeof tree.fragment === `string` ? `#${encodeUriFragment((/** @type {?} */ (tree.fragment)))}` : '';
|
1256 | return `${segment}${query}${fragment}`;
|
1257 | }
|
1258 | }
|
1259 |
|
1260 | const DEFAULT_SERIALIZER = new DefaultUrlSerializer();
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 | function serializePaths(segment) {
|
1266 | return segment.segments.map(( |
1267 |
|
1268 |
|
1269 |
|
1270 | p => serializePath(p))).join('/');
|
1271 | }
|
1272 |
|
1273 |
|
1274 |
|
1275 |
|
1276 |
|
1277 | function serializeSegment(segment, root) {
|
1278 | if (!segment.hasChildren()) {
|
1279 | return serializePaths(segment);
|
1280 | }
|
1281 | if (root) {
|
1282 |
|
1283 | const primary = segment.children[PRIMARY_OUTLET] ?
|
1284 | serializeSegment(segment.children[PRIMARY_OUTLET], false) :
|
1285 | '';
|
1286 |
|
1287 | const children = [];
|
1288 | forEach(segment.children, ( |
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 | (v, k) => {
|
1294 | if (k !== PRIMARY_OUTLET) {
|
1295 | children.push(`${k}:${serializeSegment(v, false)}`);
|
1296 | }
|
1297 | }));
|
1298 | return children.length > 0 ? `${primary}(${children.join('//')})` : primary;
|
1299 | }
|
1300 | else {
|
1301 |
|
1302 | const children = mapChildrenIntoArray(segment, ( |
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 | (v, k) => {
|
1308 | if (k === PRIMARY_OUTLET) {
|
1309 | return [serializeSegment(segment.children[PRIMARY_OUTLET], false)];
|
1310 | }
|
1311 | return [`${k}:${serializeSegment(v, false)}`];
|
1312 | }));
|
1313 | return `${serializePaths(segment)}/(${children.join('//')})`;
|
1314 | }
|
1315 | }
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 | function encodeUriString(s) {
|
1325 | return encodeURIComponent(s)
|
1326 | .replace(/%40/g, '@')
|
1327 | .replace(/%3A/gi, ':')
|
1328 | .replace(/%24/g, '$')
|
1329 | .replace(/%2C/gi, ',');
|
1330 | }
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 | function encodeUriQuery(s) {
|
1340 | return encodeUriString(s).replace(/%3B/gi, ';');
|
1341 | }
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 | function encodeUriFragment(s) {
|
1351 | return encodeURI(s);
|
1352 | }
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 | function encodeUriSegment(s) {
|
1363 | return encodeUriString(s).replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/%26/gi, '&');
|
1364 | }
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 | function decode(s) {
|
1370 | return decodeURIComponent(s);
|
1371 | }
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 | function decodeQuery(s) {
|
1379 | return decode(s.replace(/\+/g, '%20'));
|
1380 | }
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 | function serializePath(path) {
|
1386 | return `${encodeUriSegment(path.path)}${serializeMatrixParams(path.parameters)}`;
|
1387 | }
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 | function serializeMatrixParams(params) {
|
1393 | return Object.keys(params)
|
1394 | .map(( |
1395 |
|
1396 |
|
1397 |
|
1398 | key => `;${encodeUriSegment(key)}=${encodeUriSegment(params[key])}`))
|
1399 | .join('');
|
1400 | }
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 | function serializeQueryParams(params) {
|
1406 |
|
1407 | const strParams = Object.keys(params).map(( |
1408 |
|
1409 |
|
1410 |
|
1411 | (name) => {
|
1412 |
|
1413 | const value = params[name];
|
1414 | return Array.isArray(value) ?
|
1415 | value.map(( |
1416 |
|
1417 |
|
1418 |
|
1419 | v => `${encodeUriQuery(name)}=${encodeUriQuery(v)}`)).join('&') :
|
1420 | `${encodeUriQuery(name)}=${encodeUriQuery(value)}`;
|
1421 | }));
|
1422 | return strParams.length ? `?${strParams.join("&")}` : '';
|
1423 | }
|
1424 |
|
1425 | const SEGMENT_RE = /^[^\/()?;=#]+/;
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 | function matchSegments(str) {
|
1431 |
|
1432 | const match = str.match(SEGMENT_RE);
|
1433 | return match ? match[0] : '';
|
1434 | }
|
1435 |
|
1436 | const QUERY_PARAM_RE = /^[^=?&#]+/;
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 | function matchQueryParams(str) {
|
1443 |
|
1444 | const match = str.match(QUERY_PARAM_RE);
|
1445 | return match ? match[0] : '';
|
1446 | }
|
1447 |
|
1448 | const QUERY_PARAM_VALUE_RE = /^[^?&#]+/;
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 | function matchUrlQueryParamValue(str) {
|
1455 |
|
1456 | const match = str.match(QUERY_PARAM_VALUE_RE);
|
1457 | return match ? match[0] : '';
|
1458 | }
|
1459 | class UrlParser {
|
1460 | |
1461 |
|
1462 |
|
1463 | constructor(url) {
|
1464 | this.url = url;
|
1465 | this.remaining = url;
|
1466 | }
|
1467 | |
1468 |
|
1469 |
|
1470 | parseRootSegment() {
|
1471 | this.consumeOptional('/');
|
1472 | if (this.remaining === '' || this.peekStartsWith('?') || this.peekStartsWith('#')) {
|
1473 | return new UrlSegmentGroup([], {});
|
1474 | }
|
1475 |
|
1476 | return new UrlSegmentGroup([], this.parseChildren());
|
1477 | }
|
1478 | |
1479 |
|
1480 |
|
1481 | parseQueryParams() {
|
1482 |
|
1483 | const params = {};
|
1484 | if (this.consumeOptional('?')) {
|
1485 | do {
|
1486 | this.parseQueryParam(params);
|
1487 | } while (this.consumeOptional('&'));
|
1488 | }
|
1489 | return params;
|
1490 | }
|
1491 | |
1492 |
|
1493 |
|
1494 | parseFragment() {
|
1495 | return this.consumeOptional('#') ? decodeURIComponent(this.remaining) : null;
|
1496 | }
|
1497 | |
1498 |
|
1499 |
|
1500 |
|
1501 | parseChildren() {
|
1502 | if (this.remaining === '') {
|
1503 | return {};
|
1504 | }
|
1505 | this.consumeOptional('/');
|
1506 |
|
1507 | const segments = [];
|
1508 | if (!this.peekStartsWith('(')) {
|
1509 | segments.push(this.parseSegment());
|
1510 | }
|
1511 | while (this.peekStartsWith('/') && !this.peekStartsWith('//') && !this.peekStartsWith('/(')) {
|
1512 | this.capture('/');
|
1513 | segments.push(this.parseSegment());
|
1514 | }
|
1515 |
|
1516 | let children = {};
|
1517 | if (this.peekStartsWith('/(')) {
|
1518 | this.capture('/');
|
1519 | children = this.parseParens(true);
|
1520 | }
|
1521 |
|
1522 | let res = {};
|
1523 | if (this.peekStartsWith('(')) {
|
1524 | res = this.parseParens(false);
|
1525 | }
|
1526 | if (segments.length > 0 || Object.keys(children).length > 0) {
|
1527 | res[PRIMARY_OUTLET] = new UrlSegmentGroup(segments, children);
|
1528 | }
|
1529 | return res;
|
1530 | }
|
1531 |
|
1532 |
|
1533 | |
1534 |
|
1535 |
|
1536 |
|
1537 | parseSegment() {
|
1538 |
|
1539 | const path = matchSegments(this.remaining);
|
1540 | if (path === '' && this.peekStartsWith(';')) {
|
1541 | throw new Error(`Empty path url segment cannot have parameters: '${this.remaining}'.`);
|
1542 | }
|
1543 | this.capture(path);
|
1544 | return new UrlSegment(decode(path), this.parseMatrixParams());
|
1545 | }
|
1546 | |
1547 |
|
1548 |
|
1549 |
|
1550 | parseMatrixParams() {
|
1551 |
|
1552 | const params = {};
|
1553 | while (this.consumeOptional(';')) {
|
1554 | this.parseParam(params);
|
1555 | }
|
1556 | return params;
|
1557 | }
|
1558 | |
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 | parseParam(params) {
|
1564 |
|
1565 | const key = matchSegments(this.remaining);
|
1566 | if (!key) {
|
1567 | return;
|
1568 | }
|
1569 | this.capture(key);
|
1570 |
|
1571 | let value = '';
|
1572 | if (this.consumeOptional('=')) {
|
1573 |
|
1574 | const valueMatch = matchSegments(this.remaining);
|
1575 | if (valueMatch) {
|
1576 | value = valueMatch;
|
1577 | this.capture(value);
|
1578 | }
|
1579 | }
|
1580 | params[decode(key)] = decode(value);
|
1581 | }
|
1582 |
|
1583 | |
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 | parseQueryParam(params) {
|
1589 |
|
1590 | const key = matchQueryParams(this.remaining);
|
1591 | if (!key) {
|
1592 | return;
|
1593 | }
|
1594 | this.capture(key);
|
1595 |
|
1596 | let value = '';
|
1597 | if (this.consumeOptional('=')) {
|
1598 |
|
1599 | const valueMatch = matchUrlQueryParamValue(this.remaining);
|
1600 | if (valueMatch) {
|
1601 | value = valueMatch;
|
1602 | this.capture(value);
|
1603 | }
|
1604 | }
|
1605 |
|
1606 | const decodedKey = decodeQuery(key);
|
1607 |
|
1608 | const decodedVal = decodeQuery(value);
|
1609 | if (params.hasOwnProperty(decodedKey)) {
|
1610 |
|
1611 |
|
1612 | let currentVal = params[decodedKey];
|
1613 | if (!Array.isArray(currentVal)) {
|
1614 | currentVal = [currentVal];
|
1615 | params[decodedKey] = currentVal;
|
1616 | }
|
1617 | currentVal.push(decodedVal);
|
1618 | }
|
1619 | else {
|
1620 |
|
1621 | params[decodedKey] = decodedVal;
|
1622 | }
|
1623 | }
|
1624 |
|
1625 | |
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 | parseParens(allowPrimary) {
|
1631 |
|
1632 | const segments = {};
|
1633 | this.capture('(');
|
1634 | while (!this.consumeOptional(')') && this.remaining.length > 0) {
|
1635 |
|
1636 | const path = matchSegments(this.remaining);
|
1637 |
|
1638 | const next = this.remaining[path.length];
|
1639 |
|
1640 |
|
1641 | if (next !== '/' && next !== ')' && next !== ';') {
|
1642 | throw new Error(`Cannot parse url '${this.url}'`);
|
1643 | }
|
1644 |
|
1645 | let outletName = ( (undefined));
|
1646 | if (path.indexOf(':') > -1) {
|
1647 | outletName = path.substr(0, path.indexOf(':'));
|
1648 | this.capture(outletName);
|
1649 | this.capture(':');
|
1650 | }
|
1651 | else if (allowPrimary) {
|
1652 | outletName = PRIMARY_OUTLET;
|
1653 | }
|
1654 |
|
1655 | const children = this.parseChildren();
|
1656 | segments[outletName] = Object.keys(children).length === 1 ? children[PRIMARY_OUTLET] :
|
1657 | new UrlSegmentGroup([], children);
|
1658 | this.consumeOptional('//');
|
1659 | }
|
1660 | return segments;
|
1661 | }
|
1662 | |
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 | peekStartsWith(str) { return this.remaining.startsWith(str); }
|
1668 |
|
1669 | |
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 | consumeOptional(str) {
|
1675 | if (this.peekStartsWith(str)) {
|
1676 | this.remaining = this.remaining.substring(str.length);
|
1677 | return true;
|
1678 | }
|
1679 | return false;
|
1680 | }
|
1681 | |
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 | capture(str) {
|
1687 | if (!this.consumeOptional(str)) {
|
1688 | throw new Error(`Expected "${str}".`);
|
1689 | }
|
1690 | }
|
1691 | }
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 | class Tree {
|
1708 | |
1709 |
|
1710 |
|
1711 | constructor(root) { this._root = root; }
|
1712 | |
1713 |
|
1714 |
|
1715 | get root() { return this._root.value; }
|
1716 | |
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 | parent(t) {
|
1722 |
|
1723 | const p = this.pathFromRoot(t);
|
1724 | return p.length > 1 ? p[p.length - 2] : null;
|
1725 | }
|
1726 | |
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 | children(t) {
|
1732 |
|
1733 | const n = findNode(t, this._root);
|
1734 | return n ? n.children.map(( |
1735 |
|
1736 |
|
1737 |
|
1738 | t => t.value)) : [];
|
1739 | }
|
1740 | |
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 | firstChild(t) {
|
1746 |
|
1747 | const n = findNode(t, this._root);
|
1748 | return n && n.children.length > 0 ? n.children[0].value : null;
|
1749 | }
|
1750 | |
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 | siblings(t) {
|
1756 |
|
1757 | const p = findPath(t, this._root);
|
1758 | if (p.length < 2)
|
1759 | return [];
|
1760 |
|
1761 | const c = p[p.length - 2].children.map(( |
1762 |
|
1763 |
|
1764 |
|
1765 | c => c.value));
|
1766 | return c.filter(( |
1767 |
|
1768 |
|
1769 |
|
1770 | cc => cc !== t));
|
1771 | }
|
1772 | |
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 | pathFromRoot(t) { return findPath(t, this._root).map(( |
1778 |
|
1779 |
|
1780 |
|
1781 | s => s.value)); }
|
1782 | }
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 | function findNode(value, node) {
|
1791 | if (value === node.value)
|
1792 | return node;
|
1793 | for (const child of node.children) {
|
1794 |
|
1795 | const node = findNode(value, child);
|
1796 | if (node)
|
1797 | return node;
|
1798 | }
|
1799 | return null;
|
1800 | }
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 | function findPath(value, node) {
|
1809 | if (value === node.value)
|
1810 | return [node];
|
1811 | for (const child of node.children) {
|
1812 |
|
1813 | const path = findPath(value, child);
|
1814 | if (path.length) {
|
1815 | path.unshift(node);
|
1816 | return path;
|
1817 | }
|
1818 | }
|
1819 | return [];
|
1820 | }
|
1821 |
|
1822 |
|
1823 |
|
1824 | class TreeNode {
|
1825 | |
1826 |
|
1827 |
|
1828 |
|
1829 | constructor(value, children) {
|
1830 | this.value = value;
|
1831 | this.children = children;
|
1832 | }
|
1833 | |
1834 |
|
1835 |
|
1836 | toString() { return `TreeNode(${this.value})`; }
|
1837 | }
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 | function nodeChildrenAsMap(node) {
|
1845 |
|
1846 | const map = {};
|
1847 | if (node) {
|
1848 | node.children.forEach(( |
1849 |
|
1850 |
|
1851 |
|
1852 | child => map[child.value.outlet] = child));
|
1853 | }
|
1854 | return map;
|
1855 | }
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 | class RouterState extends Tree {
|
1891 | |
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 | constructor(root, snapshot) {
|
1897 | super(root);
|
1898 | this.snapshot = snapshot;
|
1899 | setRouterState(( (this)), root);
|
1900 | }
|
1901 | |
1902 |
|
1903 |
|
1904 | toString() { return this.snapshot.toString(); }
|
1905 | }
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 | function createEmptyState(urlTree, rootComponent) {
|
1912 |
|
1913 | const snapshot = createEmptyStateSnapshot(urlTree, rootComponent);
|
1914 |
|
1915 | const emptyUrl = new BehaviorSubject([new UrlSegment('', {})]);
|
1916 |
|
1917 | const emptyParams = new BehaviorSubject({});
|
1918 |
|
1919 | const emptyData = new BehaviorSubject({});
|
1920 |
|
1921 | const emptyQueryParams = new BehaviorSubject({});
|
1922 |
|
1923 | const fragment = new BehaviorSubject('');
|
1924 |
|
1925 | const activated = new ActivatedRoute(emptyUrl, emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, snapshot.root);
|
1926 | activated.snapshot = snapshot.root;
|
1927 | return new RouterState(new TreeNode(activated, []), snapshot);
|
1928 | }
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 | function createEmptyStateSnapshot(urlTree, rootComponent) {
|
1935 |
|
1936 | const emptyParams = {};
|
1937 |
|
1938 | const emptyData = {};
|
1939 |
|
1940 | const emptyQueryParams = {};
|
1941 |
|
1942 | const fragment = '';
|
1943 |
|
1944 | const activated = new ActivatedRouteSnapshot([], emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, null, urlTree.root, -1, {});
|
1945 | return new RouterStateSnapshot('', new TreeNode(activated, []));
|
1946 | }
|
1947 |
|
1948 |
|
1949 |
|
1950 |
|
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 | class ActivatedRoute {
|
1958 | |
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 | constructor(url, params, queryParams, fragment, data, outlet, component, futureSnapshot) {
|
1970 | this.url = url;
|
1971 | this.params = params;
|
1972 | this.queryParams = queryParams;
|
1973 | this.fragment = fragment;
|
1974 | this.data = data;
|
1975 | this.outlet = outlet;
|
1976 | this.component = component;
|
1977 | this._futureSnapshot = futureSnapshot;
|
1978 | }
|
1979 | |
1980 |
|
1981 |
|
1982 |
|
1983 | get routeConfig() { return this._futureSnapshot.routeConfig; }
|
1984 | |
1985 |
|
1986 |
|
1987 |
|
1988 | get root() { return this._routerState.root; }
|
1989 | |
1990 |
|
1991 |
|
1992 |
|
1993 | get parent() { return this._routerState.parent(this); }
|
1994 | |
1995 |
|
1996 |
|
1997 |
|
1998 | get firstChild() { return this._routerState.firstChild(this); }
|
1999 | |
2000 |
|
2001 |
|
2002 |
|
2003 | get children() { return this._routerState.children(this); }
|
2004 | |
2005 |
|
2006 |
|
2007 |
|
2008 | get pathFromRoot() { return this._routerState.pathFromRoot(this); }
|
2009 | |
2010 |
|
2011 |
|
2012 |
|
2013 |
|
2014 |
|
2015 | get paramMap() {
|
2016 | if (!this._paramMap) {
|
2017 | this._paramMap = this.params.pipe(map(( |
2018 |
|
2019 |
|
2020 |
|
2021 | (p) => convertToParamMap(p))));
|
2022 | }
|
2023 | return this._paramMap;
|
2024 | }
|
2025 | |
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 | get queryParamMap() {
|
2031 | if (!this._queryParamMap) {
|
2032 | this._queryParamMap =
|
2033 | this.queryParams.pipe(map(( |
2034 |
|
2035 |
|
2036 |
|
2037 | (p) => convertToParamMap(p))));
|
2038 | }
|
2039 | return this._queryParamMap;
|
2040 | }
|
2041 | |
2042 |
|
2043 |
|
2044 | toString() {
|
2045 | return this.snapshot ? this.snapshot.toString() : `Future(${this._futureSnapshot})`;
|
2046 | }
|
2047 | }
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 |
|
2056 | function inheritedParamsDataResolve(route, paramsInheritanceStrategy = 'emptyOnly') {
|
2057 |
|
2058 | const pathFromRoot = route.pathFromRoot;
|
2059 |
|
2060 | let inheritingStartingFrom = 0;
|
2061 | if (paramsInheritanceStrategy !== 'always') {
|
2062 | inheritingStartingFrom = pathFromRoot.length - 1;
|
2063 | while (inheritingStartingFrom >= 1) {
|
2064 |
|
2065 | const current = pathFromRoot[inheritingStartingFrom];
|
2066 |
|
2067 | const parent = pathFromRoot[inheritingStartingFrom - 1];
|
2068 |
|
2069 | if (current.routeConfig && current.routeConfig.path === '') {
|
2070 | inheritingStartingFrom--;
|
2071 |
|
2072 | }
|
2073 | else if (!parent.component) {
|
2074 | inheritingStartingFrom--;
|
2075 | }
|
2076 | else {
|
2077 | break;
|
2078 | }
|
2079 | }
|
2080 | }
|
2081 | return flattenInherited(pathFromRoot.slice(inheritingStartingFrom));
|
2082 | }
|
2083 |
|
2084 |
|
2085 |
|
2086 |
|
2087 |
|
2088 | function flattenInherited(pathFromRoot) {
|
2089 | return pathFromRoot.reduce(( |
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 | (res, curr) => {
|
2095 |
|
2096 | const params = Object.assign({}, res.params, curr.params);
|
2097 |
|
2098 | const data = Object.assign({}, res.data, curr.data);
|
2099 |
|
2100 | const resolve = Object.assign({}, res.resolve, curr._resolvedData);
|
2101 | return { params, data, resolve };
|
2102 | }), ( ({ params: {}, data: {}, resolve: {} })));
|
2103 | }
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 |
|
2121 |
|
2122 |
|
2123 |
|
2124 | class ActivatedRouteSnapshot {
|
2125 | |
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 |
|
2137 |
|
2138 |
|
2139 | constructor(url, params, queryParams, fragment, data, outlet, component, routeConfig, urlSegment, lastPathIndex, resolve) {
|
2140 | this.url = url;
|
2141 | this.params = params;
|
2142 | this.queryParams = queryParams;
|
2143 | this.fragment = fragment;
|
2144 | this.data = data;
|
2145 | this.outlet = outlet;
|
2146 | this.component = component;
|
2147 | this.routeConfig = routeConfig;
|
2148 | this._urlSegment = urlSegment;
|
2149 | this._lastPathIndex = lastPathIndex;
|
2150 | this._resolve = resolve;
|
2151 | }
|
2152 | |
2153 |
|
2154 |
|
2155 |
|
2156 | get root() { return this._routerState.root; }
|
2157 | |
2158 |
|
2159 |
|
2160 |
|
2161 | get parent() { return this._routerState.parent(this); }
|
2162 | |
2163 |
|
2164 |
|
2165 |
|
2166 | get firstChild() { return this._routerState.firstChild(this); }
|
2167 | |
2168 |
|
2169 |
|
2170 |
|
2171 | get children() { return this._routerState.children(this); }
|
2172 | |
2173 |
|
2174 |
|
2175 |
|
2176 | get pathFromRoot() { return this._routerState.pathFromRoot(this); }
|
2177 | |
2178 |
|
2179 |
|
2180 | get paramMap() {
|
2181 | if (!this._paramMap) {
|
2182 | this._paramMap = convertToParamMap(this.params);
|
2183 | }
|
2184 | return this._paramMap;
|
2185 | }
|
2186 | |
2187 |
|
2188 |
|
2189 | get queryParamMap() {
|
2190 | if (!this._queryParamMap) {
|
2191 | this._queryParamMap = convertToParamMap(this.queryParams);
|
2192 | }
|
2193 | return this._queryParamMap;
|
2194 | }
|
2195 | |
2196 |
|
2197 |
|
2198 | toString() {
|
2199 |
|
2200 | const url = this.url.map(( |
2201 |
|
2202 |
|
2203 |
|
2204 | segment => segment.toString())).join('/');
|
2205 |
|
2206 | const matched = this.routeConfig ? this.routeConfig.path : '';
|
2207 | return `Route(url:'${url}', path:'${matched}')`;
|
2208 | }
|
2209 | }
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
|
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 | class RouterStateSnapshot extends Tree {
|
2238 | |
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 | constructor(url, root) {
|
2244 | super(root);
|
2245 | this.url = url;
|
2246 | setRouterState(( (this)), root);
|
2247 | }
|
2248 | |
2249 |
|
2250 |
|
2251 | toString() { return serializeNode(this._root); }
|
2252 | }
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 | function setRouterState(state, node) {
|
2260 | node.value._routerState = state;
|
2261 | node.children.forEach(( |
2262 |
|
2263 |
|
2264 |
|
2265 | c => setRouterState(state, c)));
|
2266 | }
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 | function serializeNode(node) {
|
2272 |
|
2273 | const c = node.children.length > 0 ? ` { ${node.children.map(serializeNode).join(', ')} } ` : '';
|
2274 | return `${node.value}${c}`;
|
2275 | }
|
2276 |
|
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 |
|
2283 | function advanceActivatedRoute(route) {
|
2284 | if (route.snapshot) {
|
2285 |
|
2286 | const currentSnapshot = route.snapshot;
|
2287 |
|
2288 | const nextSnapshot = route._futureSnapshot;
|
2289 | route.snapshot = nextSnapshot;
|
2290 | if (!shallowEqual(currentSnapshot.queryParams, nextSnapshot.queryParams)) {
|
2291 | (( (route.queryParams))).next(nextSnapshot.queryParams);
|
2292 | }
|
2293 | if (currentSnapshot.fragment !== nextSnapshot.fragment) {
|
2294 | (( (route.fragment))).next(nextSnapshot.fragment);
|
2295 | }
|
2296 | if (!shallowEqual(currentSnapshot.params, nextSnapshot.params)) {
|
2297 | (( (route.params))).next(nextSnapshot.params);
|
2298 | }
|
2299 | if (!shallowEqualArrays(currentSnapshot.url, nextSnapshot.url)) {
|
2300 | (( (route.url))).next(nextSnapshot.url);
|
2301 | }
|
2302 | if (!shallowEqual(currentSnapshot.data, nextSnapshot.data)) {
|
2303 | (( (route.data))).next(nextSnapshot.data);
|
2304 | }
|
2305 | }
|
2306 | else {
|
2307 | route.snapshot = route._futureSnapshot;
|
2308 |
|
2309 | (( (route.data))).next(route._futureSnapshot.data);
|
2310 | }
|
2311 | }
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 | function equalParamsAndUrlSegments(a, b) {
|
2318 |
|
2319 | const equalUrlParams = shallowEqual(a.params, b.params) && equalSegments(a.url, b.url);
|
2320 |
|
2321 | const parentsMismatch = !a.parent !== !b.parent;
|
2322 | return equalUrlParams && !parentsMismatch &&
|
2323 | (!a.parent || equalParamsAndUrlSegments(a.parent, ( (b.parent))));
|
2324 | }
|
2325 |
|
2326 |
|
2327 |
|
2328 |
|
2329 |
|
2330 |
|
2331 |
|
2332 |
|
2333 |
|
2334 |
|
2335 |
|
2336 | function createRouterState(routeReuseStrategy, curr, prevState) {
|
2337 |
|
2338 | const root = createNode(routeReuseStrategy, curr._root, prevState ? prevState._root : undefined);
|
2339 | return new RouterState(root, curr);
|
2340 | }
|
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 |
|
2347 | function createNode(routeReuseStrategy, curr, prevState) {
|
2348 |
|
2349 | if (prevState && routeReuseStrategy.shouldReuseRoute(curr.value, prevState.value.snapshot)) {
|
2350 |
|
2351 | const value = prevState.value;
|
2352 | value._futureSnapshot = curr.value;
|
2353 |
|
2354 | const children = createOrReuseChildren(routeReuseStrategy, curr, prevState);
|
2355 | return new TreeNode(value, children);
|
2356 |
|
2357 | }
|
2358 | else {
|
2359 |
|
2360 | const detachedRouteHandle = ( (routeReuseStrategy.retrieve(curr.value)));
|
2361 | if (detachedRouteHandle) {
|
2362 |
|
2363 | const tree = detachedRouteHandle.route;
|
2364 | setFutureSnapshotsOfActivatedRoutes(curr, tree);
|
2365 | return tree;
|
2366 | }
|
2367 | else {
|
2368 |
|
2369 | const value = createActivatedRoute(curr.value);
|
2370 |
|
2371 | const children = curr.children.map(( |
2372 |
|
2373 |
|
2374 |
|
2375 | c => createNode(routeReuseStrategy, c)));
|
2376 | return new TreeNode(value, children);
|
2377 | }
|
2378 | }
|
2379 | }
|
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 | function setFutureSnapshotsOfActivatedRoutes(curr, result) {
|
2386 | if (curr.value.routeConfig !== result.value.routeConfig) {
|
2387 | throw new Error('Cannot reattach ActivatedRouteSnapshot created from a different route');
|
2388 | }
|
2389 | if (curr.children.length !== result.children.length) {
|
2390 | throw new Error('Cannot reattach ActivatedRouteSnapshot with a different number of children');
|
2391 | }
|
2392 | result.value._futureSnapshot = curr.value;
|
2393 | for (let i = 0; i < curr.children.length; ++i) {
|
2394 | setFutureSnapshotsOfActivatedRoutes(curr.children[i], result.children[i]);
|
2395 | }
|
2396 | }
|
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 | function createOrReuseChildren(routeReuseStrategy, curr, prevState) {
|
2404 | return curr.children.map(( |
2405 |
|
2406 |
|
2407 |
|
2408 | child => {
|
2409 | for (const p of prevState.children) {
|
2410 | if (routeReuseStrategy.shouldReuseRoute(p.value.snapshot, child.value)) {
|
2411 | return createNode(routeReuseStrategy, child, p);
|
2412 | }
|
2413 | }
|
2414 | return createNode(routeReuseStrategy, child);
|
2415 | }));
|
2416 | }
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 | function createActivatedRoute(c) {
|
2422 | return new ActivatedRoute(new BehaviorSubject(c.url), new BehaviorSubject(c.params), new BehaviorSubject(c.queryParams), new BehaviorSubject(c.fragment), new BehaviorSubject(c.data), c.outlet, c.component, c);
|
2423 | }
|
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 | function createUrlTree(route, urlTree, commands, queryParams, fragment) {
|
2438 | if (commands.length === 0) {
|
2439 | return tree(urlTree.root, urlTree.root, urlTree, queryParams, fragment);
|
2440 | }
|
2441 |
|
2442 | const nav = computeNavigation(commands);
|
2443 | if (nav.toRoot()) {
|
2444 | return tree(urlTree.root, new UrlSegmentGroup([], {}), urlTree, queryParams, fragment);
|
2445 | }
|
2446 |
|
2447 | const startingPosition = findStartingPosition(nav, urlTree, route);
|
2448 |
|
2449 | const segmentGroup = startingPosition.processChildren ?
|
2450 | updateSegmentGroupChildren(startingPosition.segmentGroup, startingPosition.index, nav.commands) :
|
2451 | updateSegmentGroup(startingPosition.segmentGroup, startingPosition.index, nav.commands);
|
2452 | return tree(startingPosition.segmentGroup, segmentGroup, urlTree, queryParams, fragment);
|
2453 | }
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 | function isMatrixParams(command) {
|
2459 | return typeof command === 'object' && command != null && !command.outlets && !command.segmentPath;
|
2460 | }
|
2461 |
|
2462 |
|
2463 |
|
2464 |
|
2465 |
|
2466 |
|
2467 |
|
2468 |
|
2469 | function tree(oldSegmentGroup, newSegmentGroup, urlTree, queryParams, fragment) {
|
2470 |
|
2471 | let qp = {};
|
2472 | if (queryParams) {
|
2473 | forEach(queryParams, ( |
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 | (value, name) => {
|
2479 | qp[name] = Array.isArray(value) ? value.map(( |
2480 |
|
2481 |
|
2482 |
|
2483 | (v) => `${v}`)) : `${value}`;
|
2484 | }));
|
2485 | }
|
2486 | if (urlTree.root === oldSegmentGroup) {
|
2487 | return new UrlTree(newSegmentGroup, qp, fragment);
|
2488 | }
|
2489 | return new UrlTree(replaceSegment(urlTree.root, oldSegmentGroup, newSegmentGroup), qp, fragment);
|
2490 | }
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 | function replaceSegment(current, oldSegment, newSegment) {
|
2498 |
|
2499 | const children = {};
|
2500 | forEach(current.children, ( |
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 | (c, outletName) => {
|
2506 | if (c === oldSegment) {
|
2507 | children[outletName] = newSegment;
|
2508 | }
|
2509 | else {
|
2510 | children[outletName] = replaceSegment(c, oldSegment, newSegment);
|
2511 | }
|
2512 | }));
|
2513 | return new UrlSegmentGroup(current.segments, children);
|
2514 | }
|
2515 | class Navigation {
|
2516 | |
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 | constructor(isAbsolute, numberOfDoubleDots, commands) {
|
2522 | this.isAbsolute = isAbsolute;
|
2523 | this.numberOfDoubleDots = numberOfDoubleDots;
|
2524 | this.commands = commands;
|
2525 | if (isAbsolute && commands.length > 0 && isMatrixParams(commands[0])) {
|
2526 | throw new Error('Root segment cannot have matrix parameters');
|
2527 | }
|
2528 |
|
2529 | const cmdWithOutlet = commands.find(( |
2530 |
|
2531 |
|
2532 |
|
2533 | c => typeof c === 'object' && c != null && c.outlets));
|
2534 | if (cmdWithOutlet && cmdWithOutlet !== last(commands)) {
|
2535 | throw new Error('{outlets:{}} has to be the last command');
|
2536 | }
|
2537 | }
|
2538 | |
2539 |
|
2540 |
|
2541 | toRoot() {
|
2542 | return this.isAbsolute && this.commands.length === 1 && this.commands[0] == '/';
|
2543 | }
|
2544 | }
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 | function computeNavigation(commands) {
|
2551 | if ((typeof commands[0] === 'string') && commands.length === 1 && commands[0] === '/') {
|
2552 | return new Navigation(true, 0, commands);
|
2553 | }
|
2554 |
|
2555 | let numberOfDoubleDots = 0;
|
2556 |
|
2557 | let isAbsolute = false;
|
2558 |
|
2559 | const res = commands.reduce(( |
2560 |
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 | (res, cmd, cmdIdx) => {
|
2566 | if (typeof cmd === 'object' && cmd != null) {
|
2567 | if (cmd.outlets) {
|
2568 |
|
2569 | const outlets = {};
|
2570 | forEach(cmd.outlets, ( |
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 | (commands, name) => {
|
2576 | outlets[name] = typeof commands === 'string' ? commands.split('/') : commands;
|
2577 | }));
|
2578 | return [...res, { outlets }];
|
2579 | }
|
2580 | if (cmd.segmentPath) {
|
2581 | return [...res, cmd.segmentPath];
|
2582 | }
|
2583 | }
|
2584 | if (!(typeof cmd === 'string')) {
|
2585 | return [...res, cmd];
|
2586 | }
|
2587 | if (cmdIdx === 0) {
|
2588 | cmd.split('/').forEach(( |
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 | (urlPart, partIndex) => {
|
2594 | if (partIndex == 0 && urlPart === '.') ;
|
2595 | else if (partIndex == 0 && urlPart === '') {
|
2596 | isAbsolute = true;
|
2597 | }
|
2598 | else if (urlPart === '..') {
|
2599 | numberOfDoubleDots++;
|
2600 | }
|
2601 | else if (urlPart != '') {
|
2602 | res.push(urlPart);
|
2603 | }
|
2604 | }));
|
2605 | return res;
|
2606 | }
|
2607 | return [...res, cmd];
|
2608 | }), []);
|
2609 | return new Navigation(isAbsolute, numberOfDoubleDots, res);
|
2610 | }
|
2611 | class Position {
|
2612 | |
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 | constructor(segmentGroup, processChildren, index) {
|
2618 | this.segmentGroup = segmentGroup;
|
2619 | this.processChildren = processChildren;
|
2620 | this.index = index;
|
2621 | }
|
2622 | }
|
2623 |
|
2624 |
|
2625 |
|
2626 |
|
2627 |
|
2628 |
|
2629 | function findStartingPosition(nav, tree, route) {
|
2630 | if (nav.isAbsolute) {
|
2631 | return new Position(tree.root, true, 0);
|
2632 | }
|
2633 | if (route.snapshot._lastPathIndex === -1) {
|
2634 | return new Position(route.snapshot._urlSegment, true, 0);
|
2635 | }
|
2636 |
|
2637 | const modifier = isMatrixParams(nav.commands[0]) ? 0 : 1;
|
2638 |
|
2639 | const index = route.snapshot._lastPathIndex + modifier;
|
2640 | return createPositionApplyingDoubleDots(route.snapshot._urlSegment, index, nav.numberOfDoubleDots);
|
2641 | }
|
2642 |
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 | function createPositionApplyingDoubleDots(group, index, numberOfDoubleDots) {
|
2649 |
|
2650 | let g = group;
|
2651 |
|
2652 | let ci = index;
|
2653 |
|
2654 | let dd = numberOfDoubleDots;
|
2655 | while (dd > ci) {
|
2656 | dd -= ci;
|
2657 | g = ( (g.parent));
|
2658 | if (!g) {
|
2659 | throw new Error('Invalid number of \'../\'');
|
2660 | }
|
2661 | ci = g.segments.length;
|
2662 | }
|
2663 | return new Position(g, false, ci - dd);
|
2664 | }
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 | function getPath(command) {
|
2670 | if (typeof command === 'object' && command != null && command.outlets) {
|
2671 | return command.outlets[PRIMARY_OUTLET];
|
2672 | }
|
2673 | return `${command}`;
|
2674 | }
|
2675 |
|
2676 |
|
2677 |
|
2678 |
|
2679 | function getOutlets(commands) {
|
2680 | if (!(typeof commands[0] === 'object'))
|
2681 | return { [PRIMARY_OUTLET]: commands };
|
2682 | if (commands[0].outlets === undefined)
|
2683 | return { [PRIMARY_OUTLET]: commands };
|
2684 | return commands[0].outlets;
|
2685 | }
|
2686 |
|
2687 |
|
2688 |
|
2689 |
|
2690 |
|
2691 |
|
2692 | function updateSegmentGroup(segmentGroup, startIndex, commands) {
|
2693 | if (!segmentGroup) {
|
2694 | segmentGroup = new UrlSegmentGroup([], {});
|
2695 | }
|
2696 | if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
|
2697 | return updateSegmentGroupChildren(segmentGroup, startIndex, commands);
|
2698 | }
|
2699 |
|
2700 | const m = prefixedWith(segmentGroup, startIndex, commands);
|
2701 |
|
2702 | const slicedCommands = commands.slice(m.commandIndex);
|
2703 | if (m.match && m.pathIndex < segmentGroup.segments.length) {
|
2704 |
|
2705 | const g = new UrlSegmentGroup(segmentGroup.segments.slice(0, m.pathIndex), {});
|
2706 | g.children[PRIMARY_OUTLET] =
|
2707 | new UrlSegmentGroup(segmentGroup.segments.slice(m.pathIndex), segmentGroup.children);
|
2708 | return updateSegmentGroupChildren(g, 0, slicedCommands);
|
2709 | }
|
2710 | else if (m.match && slicedCommands.length === 0) {
|
2711 | return new UrlSegmentGroup(segmentGroup.segments, {});
|
2712 | }
|
2713 | else if (m.match && !segmentGroup.hasChildren()) {
|
2714 | return createNewSegmentGroup(segmentGroup, startIndex, commands);
|
2715 | }
|
2716 | else if (m.match) {
|
2717 | return updateSegmentGroupChildren(segmentGroup, 0, slicedCommands);
|
2718 | }
|
2719 | else {
|
2720 | return createNewSegmentGroup(segmentGroup, startIndex, commands);
|
2721 | }
|
2722 | }
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 | function updateSegmentGroupChildren(segmentGroup, startIndex, commands) {
|
2730 | if (commands.length === 0) {
|
2731 | return new UrlSegmentGroup(segmentGroup.segments, {});
|
2732 | }
|
2733 | else {
|
2734 |
|
2735 | const outlets = getOutlets(commands);
|
2736 |
|
2737 | const children = {};
|
2738 | forEach(outlets, ( |
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 | (commands, outlet) => {
|
2744 | if (commands !== null) {
|
2745 | children[outlet] = updateSegmentGroup(segmentGroup.children[outlet], startIndex, commands);
|
2746 | }
|
2747 | }));
|
2748 | forEach(segmentGroup.children, ( |
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 | (child, childOutlet) => {
|
2754 | if (outlets[childOutlet] === undefined) {
|
2755 | children[childOutlet] = child;
|
2756 | }
|
2757 | }));
|
2758 | return new UrlSegmentGroup(segmentGroup.segments, children);
|
2759 | }
|
2760 | }
|
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 | function prefixedWith(segmentGroup, startIndex, commands) {
|
2768 |
|
2769 | let currentCommandIndex = 0;
|
2770 |
|
2771 | let currentPathIndex = startIndex;
|
2772 |
|
2773 | const noMatch = { match: false, pathIndex: 0, commandIndex: 0 };
|
2774 | while (currentPathIndex < segmentGroup.segments.length) {
|
2775 | if (currentCommandIndex >= commands.length)
|
2776 | return noMatch;
|
2777 |
|
2778 | const path = segmentGroup.segments[currentPathIndex];
|
2779 |
|
2780 | const curr = getPath(commands[currentCommandIndex]);
|
2781 |
|
2782 | const next = currentCommandIndex < commands.length - 1 ? commands[currentCommandIndex + 1] : null;
|
2783 | if (currentPathIndex > 0 && curr === undefined)
|
2784 | break;
|
2785 | if (curr && next && (typeof next === 'object') && next.outlets === undefined) {
|
2786 | if (!compare(curr, next, path))
|
2787 | return noMatch;
|
2788 | currentCommandIndex += 2;
|
2789 | }
|
2790 | else {
|
2791 | if (!compare(curr, {}, path))
|
2792 | return noMatch;
|
2793 | currentCommandIndex++;
|
2794 | }
|
2795 | currentPathIndex++;
|
2796 | }
|
2797 | return { match: true, pathIndex: currentPathIndex, commandIndex: currentCommandIndex };
|
2798 | }
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 | function createNewSegmentGroup(segmentGroup, startIndex, commands) {
|
2806 |
|
2807 | const paths = segmentGroup.segments.slice(0, startIndex);
|
2808 |
|
2809 | let i = 0;
|
2810 | while (i < commands.length) {
|
2811 | if (typeof commands[i] === 'object' && commands[i].outlets !== undefined) {
|
2812 |
|
2813 | const children = createNewSegmentChildren(commands[i].outlets);
|
2814 | return new UrlSegmentGroup(paths, children);
|
2815 | }
|
2816 |
|
2817 | if (i === 0 && isMatrixParams(commands[0])) {
|
2818 |
|
2819 | const p = segmentGroup.segments[startIndex];
|
2820 | paths.push(new UrlSegment(p.path, commands[0]));
|
2821 | i++;
|
2822 | continue;
|
2823 | }
|
2824 |
|
2825 | const curr = getPath(commands[i]);
|
2826 |
|
2827 | const next = (i < commands.length - 1) ? commands[i + 1] : null;
|
2828 | if (curr && next && isMatrixParams(next)) {
|
2829 | paths.push(new UrlSegment(curr, stringify(next)));
|
2830 | i += 2;
|
2831 | }
|
2832 | else {
|
2833 | paths.push(new UrlSegment(curr, {}));
|
2834 | i++;
|
2835 | }
|
2836 | }
|
2837 | return new UrlSegmentGroup(paths, {});
|
2838 | }
|
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 | function createNewSegmentChildren(outlets) {
|
2844 |
|
2845 | const children = {};
|
2846 | forEach(outlets, ( |
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 | (commands, outlet) => {
|
2852 | if (commands !== null) {
|
2853 | children[outlet] = createNewSegmentGroup(new UrlSegmentGroup([], {}), 0, commands);
|
2854 | }
|
2855 | }));
|
2856 | return children;
|
2857 | }
|
2858 |
|
2859 |
|
2860 |
|
2861 |
|
2862 | function stringify(params) {
|
2863 |
|
2864 | const res = {};
|
2865 | forEach(params, ( |
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 | (v, k) => res[k] = `${v}`));
|
2871 | return res;
|
2872 | }
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 |
|
2879 | function compare(path, params, segment) {
|
2880 | return path == segment.path && shallowEqual(params, segment.parameters);
|
2881 | }
|
2882 |
|
2883 |
|
2884 |
|
2885 |
|
2886 |
|
2887 |
|
2888 | const activateRoutes = ( |
2889 |
|
2890 |
|
2891 |
|
2892 |
|
2893 |
|
2894 | (rootContexts, routeReuseStrategy, forwardEvent) => map(( |
2895 |
|
2896 |
|
2897 |
|
2898 | t => {
|
2899 | new ActivateRoutes(routeReuseStrategy, ( (t.targetRouterState)), t.currentRouterState, forwardEvent)
|
2900 | .activate(rootContexts);
|
2901 | return t;
|
2902 | })));
|
2903 | class ActivateRoutes {
|
2904 | |
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 | constructor(routeReuseStrategy, futureState, currState, forwardEvent) {
|
2911 | this.routeReuseStrategy = routeReuseStrategy;
|
2912 | this.futureState = futureState;
|
2913 | this.currState = currState;
|
2914 | this.forwardEvent = forwardEvent;
|
2915 | }
|
2916 | |
2917 |
|
2918 |
|
2919 |
|
2920 | activate(parentContexts) {
|
2921 |
|
2922 | const futureRoot = this.futureState._root;
|
2923 |
|
2924 | const currRoot = this.currState ? this.currState._root : null;
|
2925 | this.deactivateChildRoutes(futureRoot, currRoot, parentContexts);
|
2926 | advanceActivatedRoute(this.futureState.root);
|
2927 | this.activateChildRoutes(futureRoot, currRoot, parentContexts);
|
2928 | }
|
2929 |
|
2930 | |
2931 |
|
2932 |
|
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 | deactivateChildRoutes(futureNode, currNode, contexts) {
|
2938 |
|
2939 | const children = nodeChildrenAsMap(currNode);
|
2940 |
|
2941 | futureNode.children.forEach(( |
2942 |
|
2943 |
|
2944 |
|
2945 | futureChild => {
|
2946 |
|
2947 | const childOutletName = futureChild.value.outlet;
|
2948 | this.deactivateRoutes(futureChild, children[childOutletName], contexts);
|
2949 | delete children[childOutletName];
|
2950 | }));
|
2951 |
|
2952 | forEach(children, ( |
2953 |
|
2954 |
|
2955 |
|
2956 |
|
2957 | (v, childName) => {
|
2958 | this.deactivateRouteAndItsChildren(v, contexts);
|
2959 | }));
|
2960 | }
|
2961 | |
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 | deactivateRoutes(futureNode, currNode, parentContext) {
|
2969 |
|
2970 | const future = futureNode.value;
|
2971 |
|
2972 | const curr = currNode ? currNode.value : null;
|
2973 | if (future === curr) {
|
2974 |
|
2975 | if (future.component) {
|
2976 |
|
2977 |
|
2978 | const context = parentContext.getContext(future.outlet);
|
2979 | if (context) {
|
2980 | this.deactivateChildRoutes(futureNode, currNode, context.children);
|
2981 | }
|
2982 | }
|
2983 | else {
|
2984 |
|
2985 | this.deactivateChildRoutes(futureNode, currNode, parentContext);
|
2986 | }
|
2987 | }
|
2988 | else {
|
2989 | if (curr) {
|
2990 |
|
2991 | this.deactivateRouteAndItsChildren(currNode, parentContext);
|
2992 | }
|
2993 | }
|
2994 | }
|
2995 | |
2996 |
|
2997 |
|
2998 |
|
2999 |
|
3000 |
|
3001 | deactivateRouteAndItsChildren(route, parentContexts) {
|
3002 | if (this.routeReuseStrategy.shouldDetach(route.value.snapshot)) {
|
3003 | this.detachAndStoreRouteSubtree(route, parentContexts);
|
3004 | }
|
3005 | else {
|
3006 | this.deactivateRouteAndOutlet(route, parentContexts);
|
3007 | }
|
3008 | }
|
3009 | |
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 | detachAndStoreRouteSubtree(route, parentContexts) {
|
3016 |
|
3017 | const context = parentContexts.getContext(route.value.outlet);
|
3018 | if (context && context.outlet) {
|
3019 |
|
3020 | const componentRef = context.outlet.detach();
|
3021 |
|
3022 | const contexts = context.children.onOutletDeactivated();
|
3023 | this.routeReuseStrategy.store(route.value.snapshot, { componentRef, route, contexts });
|
3024 | }
|
3025 | }
|
3026 | |
3027 |
|
3028 |
|
3029 |
|
3030 |
|
3031 |
|
3032 | deactivateRouteAndOutlet(route, parentContexts) {
|
3033 |
|
3034 | const context = parentContexts.getContext(route.value.outlet);
|
3035 | if (context) {
|
3036 |
|
3037 | const children = nodeChildrenAsMap(route);
|
3038 |
|
3039 | const contexts = route.value.component ? context.children : parentContexts;
|
3040 | forEach(children, ( |
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 | (v, k) => this.deactivateRouteAndItsChildren(v, contexts)));
|
3046 | if (context.outlet) {
|
3047 |
|
3048 | context.outlet.deactivate();
|
3049 |
|
3050 | context.children.onOutletDeactivated();
|
3051 | }
|
3052 | }
|
3053 | }
|
3054 | |
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 | activateChildRoutes(futureNode, currNode, contexts) {
|
3062 |
|
3063 | const children = nodeChildrenAsMap(currNode);
|
3064 | futureNode.children.forEach(( |
3065 |
|
3066 |
|
3067 |
|
3068 | c => {
|
3069 | this.activateRoutes(c, children[c.value.outlet], contexts);
|
3070 | this.forwardEvent(new ActivationEnd(c.value.snapshot));
|
3071 | }));
|
3072 | if (futureNode.children.length) {
|
3073 | this.forwardEvent(new ChildActivationEnd(futureNode.value.snapshot));
|
3074 | }
|
3075 | }
|
3076 | |
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 | activateRoutes(futureNode, currNode, parentContexts) {
|
3084 |
|
3085 | const future = futureNode.value;
|
3086 |
|
3087 | const curr = currNode ? currNode.value : null;
|
3088 | advanceActivatedRoute(future);
|
3089 |
|
3090 | if (future === curr) {
|
3091 | if (future.component) {
|
3092 |
|
3093 |
|
3094 | const context = parentContexts.getOrCreateContext(future.outlet);
|
3095 | this.activateChildRoutes(futureNode, currNode, context.children);
|
3096 | }
|
3097 | else {
|
3098 |
|
3099 | this.activateChildRoutes(futureNode, currNode, parentContexts);
|
3100 | }
|
3101 | }
|
3102 | else {
|
3103 | if (future.component) {
|
3104 |
|
3105 |
|
3106 | const context = parentContexts.getOrCreateContext(future.outlet);
|
3107 | if (this.routeReuseStrategy.shouldAttach(future.snapshot)) {
|
3108 |
|
3109 | const stored = (( (this.routeReuseStrategy.retrieve(future.snapshot))));
|
3110 | this.routeReuseStrategy.store(future.snapshot, null);
|
3111 | context.children.onOutletReAttached(stored.contexts);
|
3112 | context.attachRef = stored.componentRef;
|
3113 | context.route = stored.route.value;
|
3114 | if (context.outlet) {
|
3115 |
|
3116 |
|
3117 | context.outlet.attach(stored.componentRef, stored.route.value);
|
3118 | }
|
3119 | advanceActivatedRouteNodeAndItsChildren(stored.route);
|
3120 | }
|
3121 | else {
|
3122 |
|
3123 | const config = parentLoadedConfig(future.snapshot);
|
3124 |
|
3125 | const cmpFactoryResolver = config ? config.module.componentFactoryResolver : null;
|
3126 | context.attachRef = null;
|
3127 | context.route = future;
|
3128 | context.resolver = cmpFactoryResolver;
|
3129 | if (context.outlet) {
|
3130 |
|
3131 |
|
3132 | context.outlet.activateWith(future, cmpFactoryResolver);
|
3133 | }
|
3134 | this.activateChildRoutes(futureNode, null, context.children);
|
3135 | }
|
3136 | }
|
3137 | else {
|
3138 |
|
3139 | this.activateChildRoutes(futureNode, null, parentContexts);
|
3140 | }
|
3141 | }
|
3142 | }
|
3143 | }
|
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 | function advanceActivatedRouteNodeAndItsChildren(node) {
|
3149 | advanceActivatedRoute(node.value);
|
3150 | node.children.forEach(advanceActivatedRouteNodeAndItsChildren);
|
3151 | }
|
3152 |
|
3153 |
|
3154 |
|
3155 |
|
3156 | function parentLoadedConfig(snapshot) {
|
3157 | for (let s = snapshot.parent; s; s = s.parent) {
|
3158 |
|
3159 | const route = s.routeConfig;
|
3160 | if (route && route._loadedConfig)
|
3161 | return route._loadedConfig;
|
3162 | if (route && route.component)
|
3163 | return null;
|
3164 | }
|
3165 | return null;
|
3166 | }
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 | function isFunction(v) {
|
3189 | return typeof v === 'function';
|
3190 | }
|
3191 |
|
3192 |
|
3193 |
|
3194 |
|
3195 | function isBoolean(v) {
|
3196 | return typeof v === 'boolean';
|
3197 | }
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 | function isUrlTree(v) {
|
3203 | return v instanceof UrlTree;
|
3204 | }
|
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 | function isCanLoad(guard) {
|
3210 | return guard && isFunction(guard.canLoad);
|
3211 | }
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 | function isCanActivate(guard) {
|
3217 | return guard && isFunction(guard.canActivate);
|
3218 | }
|
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 | function isCanActivateChild(guard) {
|
3224 | return guard && isFunction(guard.canActivateChild);
|
3225 | }
|
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 | function isCanDeactivate(guard) {
|
3232 | return guard && isFunction(guard.canDeactivate);
|
3233 | }
|
3234 |
|
3235 |
|
3236 |
|
3237 |
|
3238 |
|
3239 | class NoMatch {
|
3240 | |
3241 |
|
3242 |
|
3243 | constructor(segmentGroup) { this.segmentGroup = segmentGroup || null; }
|
3244 | }
|
3245 | class AbsoluteRedirect {
|
3246 | |
3247 |
|
3248 |
|
3249 | constructor(urlTree) {
|
3250 | this.urlTree = urlTree;
|
3251 | }
|
3252 | }
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 | function noMatch(segmentGroup) {
|
3258 | return new Observable(( |
3259 |
|
3260 |
|
3261 |
|
3262 | (obs) => obs.error(new NoMatch(segmentGroup))));
|
3263 | }
|
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 | function absoluteRedirect(newTree) {
|
3269 | return new Observable(( |
3270 |
|
3271 |
|
3272 |
|
3273 | (obs) => obs.error(new AbsoluteRedirect(newTree))));
|
3274 | }
|
3275 |
|
3276 |
|
3277 |
|
3278 |
|
3279 | function namedOutletsRedirect(redirectTo) {
|
3280 | return new Observable(( |
3281 |
|
3282 |
|
3283 |
|
3284 | (obs) => obs.error(new Error(`Only absolute redirects can have named outlets. redirectTo: '${redirectTo}'`))));
|
3285 | }
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 | function canLoadFails(route) {
|
3291 | return new Observable(( |
3292 |
|
3293 |
|
3294 |
|
3295 | (obs) => obs.error(navigationCancelingError(`Cannot load children because the guard of the route "path: '${route.path}'" returned false`))));
|
3296 | }
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 | function applyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config) {
|
3309 | return new ApplyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config).apply();
|
3310 | }
|
3311 | class ApplyRedirects {
|
3312 | |
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 | constructor(moduleInjector, configLoader, urlSerializer, urlTree, config) {
|
3320 | this.configLoader = configLoader;
|
3321 | this.urlSerializer = urlSerializer;
|
3322 | this.urlTree = urlTree;
|
3323 | this.config = config;
|
3324 | this.allowRedirects = true;
|
3325 | this.ngModule = moduleInjector.get(NgModuleRef);
|
3326 | }
|
3327 | |
3328 |
|
3329 |
|
3330 | apply() {
|
3331 |
|
3332 | const expanded$ = this.expandSegmentGroup(this.ngModule, this.config, this.urlTree.root, PRIMARY_OUTLET);
|
3333 |
|
3334 | const urlTrees$ = expanded$.pipe(map(( |
3335 |
|
3336 |
|
3337 |
|
3338 | (rootSegmentGroup) => this.createUrlTree(rootSegmentGroup, this.urlTree.queryParams, ( (this.urlTree.fragment))))));
|
3339 | return urlTrees$.pipe(catchError(( |
3340 |
|
3341 |
|
3342 |
|
3343 | (e) => {
|
3344 | if (e instanceof AbsoluteRedirect) {
|
3345 |
|
3346 | this.allowRedirects = false;
|
3347 |
|
3348 | return this.match(e.urlTree);
|
3349 | }
|
3350 | if (e instanceof NoMatch) {
|
3351 | throw this.noMatchError(e);
|
3352 | }
|
3353 | throw e;
|
3354 | })));
|
3355 | }
|
3356 | |
3357 |
|
3358 |
|
3359 |
|
3360 |
|
3361 | match(tree) {
|
3362 |
|
3363 | const expanded$ = this.expandSegmentGroup(this.ngModule, this.config, tree.root, PRIMARY_OUTLET);
|
3364 |
|
3365 | const mapped$ = expanded$.pipe(map(( |
3366 |
|
3367 |
|
3368 |
|
3369 | (rootSegmentGroup) => this.createUrlTree(rootSegmentGroup, tree.queryParams, ( (tree.fragment))))));
|
3370 | return mapped$.pipe(catchError(( |
3371 |
|
3372 |
|
3373 |
|
3374 | (e) => {
|
3375 | if (e instanceof NoMatch) {
|
3376 | throw this.noMatchError(e);
|
3377 | }
|
3378 | throw e;
|
3379 | })));
|
3380 | }
|
3381 | |
3382 |
|
3383 |
|
3384 |
|
3385 |
|
3386 | noMatchError(e) {
|
3387 | return new Error(`Cannot match any routes. URL Segment: '${e.segmentGroup}'`);
|
3388 | }
|
3389 | |
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 | createUrlTree(rootCandidate, queryParams, fragment) {
|
3397 |
|
3398 | const root = rootCandidate.segments.length > 0 ?
|
3399 | new UrlSegmentGroup([], { [PRIMARY_OUTLET]: rootCandidate }) :
|
3400 | rootCandidate;
|
3401 | return new UrlTree(root, queryParams, fragment);
|
3402 | }
|
3403 | |
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 | expandSegmentGroup(ngModule, routes, segmentGroup, outlet) {
|
3412 | if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
|
3413 | return this.expandChildren(ngModule, routes, segmentGroup)
|
3414 | .pipe(map(( |
3415 |
|
3416 |
|
3417 |
|
3418 | (children) => new UrlSegmentGroup([], children))));
|
3419 | }
|
3420 | return this.expandSegment(ngModule, segmentGroup, routes, segmentGroup.segments, outlet, true);
|
3421 | }
|
3422 |
|
3423 | |
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 |
|
3430 | expandChildren(ngModule, routes, segmentGroup) {
|
3431 | return waitForMap(segmentGroup.children, ( |
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 | (childOutlet, child) => this.expandSegmentGroup(ngModule, routes, child, childOutlet)));
|
3437 | }
|
3438 | |
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 |
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 | expandSegment(ngModule, segmentGroup, routes, segments, outlet, allowRedirects) {
|
3449 | return of(...routes).pipe(map(( |
3450 |
|
3451 |
|
3452 |
|
3453 | (r) => {
|
3454 |
|
3455 | const expanded$ = this.expandSegmentAgainstRoute(ngModule, segmentGroup, routes, r, segments, outlet, allowRedirects);
|
3456 | return expanded$.pipe(catchError(( |
3457 |
|
3458 |
|
3459 |
|
3460 | (e) => {
|
3461 | if (e instanceof NoMatch) {
|
3462 |
|
3463 |
|
3464 | return ( (of(null)));
|
3465 | }
|
3466 | throw e;
|
3467 | })));
|
3468 | })), concatAll(), first(( |
3469 |
|
3470 |
|
3471 |
|
3472 | (s) => !!s)), catchError(( |
3473 |
|
3474 |
|
3475 |
|
3476 |
|
3477 | (e, _) => {
|
3478 | if (e instanceof EmptyError || e.name === 'EmptyError') {
|
3479 | if (this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
|
3480 | return of(new UrlSegmentGroup([], {}));
|
3481 | }
|
3482 | throw new NoMatch(segmentGroup);
|
3483 | }
|
3484 | throw e;
|
3485 | })));
|
3486 | }
|
3487 | |
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 | noLeftoversInUrl(segmentGroup, segments, outlet) {
|
3495 | return segments.length === 0 && !segmentGroup.children[outlet];
|
3496 | }
|
3497 | |
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 | expandSegmentAgainstRoute(ngModule, segmentGroup, routes, route, paths, outlet, allowRedirects) {
|
3509 | if (getOutlet(route) !== outlet) {
|
3510 | return noMatch(segmentGroup);
|
3511 | }
|
3512 | if (route.redirectTo === undefined) {
|
3513 | return this.matchSegmentAgainstRoute(ngModule, segmentGroup, route, paths);
|
3514 | }
|
3515 | if (allowRedirects && this.allowRedirects) {
|
3516 | return this.expandSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, paths, outlet);
|
3517 | }
|
3518 | return noMatch(segmentGroup);
|
3519 | }
|
3520 | |
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 | expandSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, segments, outlet) {
|
3531 | if (route.path === '**') {
|
3532 | return this.expandWildCardWithParamsAgainstRouteUsingRedirect(ngModule, routes, route, outlet);
|
3533 | }
|
3534 | return this.expandRegularSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, segments, outlet);
|
3535 | }
|
3536 | |
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 | expandWildCardWithParamsAgainstRouteUsingRedirect(ngModule, routes, route, outlet) {
|
3545 |
|
3546 | const newTree = this.applyRedirectCommands([], ( (route.redirectTo)), {});
|
3547 | if (( (route.redirectTo)).startsWith('/')) {
|
3548 | return absoluteRedirect(newTree);
|
3549 | }
|
3550 | return this.lineralizeSegments(route, newTree).pipe(mergeMap(( |
3551 |
|
3552 |
|
3553 |
|
3554 | (newSegments) => {
|
3555 |
|
3556 | const group = new UrlSegmentGroup(newSegments, {});
|
3557 | return this.expandSegment(ngModule, group, routes, newSegments, outlet, false);
|
3558 | })));
|
3559 | }
|
3560 | |
3561 |
|
3562 |
|
3563 |
|
3564 |
|
3565 |
|
3566 |
|
3567 |
|
3568 |
|
3569 |
|
3570 | expandRegularSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, segments, outlet) {
|
3571 | const { matched, consumedSegments, lastChild, positionalParamSegments } = match(segmentGroup, route, segments);
|
3572 | if (!matched)
|
3573 | return noMatch(segmentGroup);
|
3574 |
|
3575 | const newTree = this.applyRedirectCommands(consumedSegments, ( (route.redirectTo)), ( (positionalParamSegments)));
|
3576 | if (( (route.redirectTo)).startsWith('/')) {
|
3577 | return absoluteRedirect(newTree);
|
3578 | }
|
3579 | return this.lineralizeSegments(route, newTree).pipe(mergeMap(( |
3580 |
|
3581 |
|
3582 |
|
3583 | (newSegments) => {
|
3584 | return this.expandSegment(ngModule, segmentGroup, routes, newSegments.concat(segments.slice(lastChild)), outlet, false);
|
3585 | })));
|
3586 | }
|
3587 | |
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 | matchSegmentAgainstRoute(ngModule, rawSegmentGroup, route, segments) {
|
3596 | if (route.path === '**') {
|
3597 | if (route.loadChildren) {
|
3598 | return this.configLoader.load(ngModule.injector, route)
|
3599 | .pipe(map(( |
3600 |
|
3601 |
|
3602 |
|
3603 | (cfg) => {
|
3604 | route._loadedConfig = cfg;
|
3605 | return new UrlSegmentGroup(segments, {});
|
3606 | })));
|
3607 | }
|
3608 | return of(new UrlSegmentGroup(segments, {}));
|
3609 | }
|
3610 | const { matched, consumedSegments, lastChild } = match(rawSegmentGroup, route, segments);
|
3611 | if (!matched)
|
3612 | return noMatch(rawSegmentGroup);
|
3613 |
|
3614 | const rawSlicedSegments = segments.slice(lastChild);
|
3615 |
|
3616 | const childConfig$ = this.getChildConfig(ngModule, route, segments);
|
3617 | return childConfig$.pipe(mergeMap(( |
3618 |
|
3619 |
|
3620 |
|
3621 | (routerConfig) => {
|
3622 |
|
3623 | const childModule = routerConfig.module;
|
3624 |
|
3625 | const childConfig = routerConfig.routes;
|
3626 | const { segmentGroup, slicedSegments } = split(rawSegmentGroup, consumedSegments, rawSlicedSegments, childConfig);
|
3627 | if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
|
3628 |
|
3629 | const expanded$ = this.expandChildren(childModule, childConfig, segmentGroup);
|
3630 | return expanded$.pipe(map(( |
3631 |
|
3632 |
|
3633 |
|
3634 | (children) => new UrlSegmentGroup(consumedSegments, children))));
|
3635 | }
|
3636 | if (childConfig.length === 0 && slicedSegments.length === 0) {
|
3637 | return of(new UrlSegmentGroup(consumedSegments, {}));
|
3638 | }
|
3639 |
|
3640 | const expanded$ = this.expandSegment(childModule, segmentGroup, childConfig, slicedSegments, PRIMARY_OUTLET, true);
|
3641 | return expanded$.pipe(map(( |
3642 |
|
3643 |
|
3644 |
|
3645 | (cs) => new UrlSegmentGroup(consumedSegments.concat(cs.segments), cs.children))));
|
3646 | })));
|
3647 | }
|
3648 | |
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 | getChildConfig(ngModule, route, segments) {
|
3656 | if (route.children) {
|
3657 |
|
3658 | return of(new LoadedRouterConfig(route.children, ngModule));
|
3659 | }
|
3660 | if (route.loadChildren) {
|
3661 |
|
3662 | if (route._loadedConfig !== undefined) {
|
3663 | return of(route._loadedConfig);
|
3664 | }
|
3665 | return runCanLoadGuard(ngModule.injector, route, segments)
|
3666 | .pipe(mergeMap(( |
3667 |
|
3668 |
|
3669 |
|
3670 | (shouldLoad) => {
|
3671 | if (shouldLoad) {
|
3672 | return this.configLoader.load(ngModule.injector, route)
|
3673 | .pipe(map(( |
3674 |
|
3675 |
|
3676 |
|
3677 | (cfg) => {
|
3678 | route._loadedConfig = cfg;
|
3679 | return cfg;
|
3680 | })));
|
3681 | }
|
3682 | return canLoadFails(route);
|
3683 | })));
|
3684 | }
|
3685 | return of(new LoadedRouterConfig([], ngModule));
|
3686 | }
|
3687 | |
3688 |
|
3689 |
|
3690 |
|
3691 |
|
3692 |
|
3693 | lineralizeSegments(route, urlTree) {
|
3694 |
|
3695 | let res = [];
|
3696 |
|
3697 | let c = urlTree.root;
|
3698 | while (true) {
|
3699 | res = res.concat(c.segments);
|
3700 | if (c.numberOfChildren === 0) {
|
3701 | return of(res);
|
3702 | }
|
3703 | if (c.numberOfChildren > 1 || !c.children[PRIMARY_OUTLET]) {
|
3704 | return namedOutletsRedirect(( (route.redirectTo)));
|
3705 | }
|
3706 | c = c.children[PRIMARY_OUTLET];
|
3707 | }
|
3708 | }
|
3709 | |
3710 |
|
3711 |
|
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 | applyRedirectCommands(segments, redirectTo, posParams) {
|
3717 | return this.applyRedirectCreatreUrlTree(redirectTo, this.urlSerializer.parse(redirectTo), segments, posParams);
|
3718 | }
|
3719 | |
3720 |
|
3721 |
|
3722 |
|
3723 |
|
3724 |
|
3725 |
|
3726 |
|
3727 | applyRedirectCreatreUrlTree(redirectTo, urlTree, segments, posParams) {
|
3728 |
|
3729 | const newRoot = this.createSegmentGroup(redirectTo, urlTree.root, segments, posParams);
|
3730 | return new UrlTree(newRoot, this.createQueryParams(urlTree.queryParams, this.urlTree.queryParams), urlTree.fragment);
|
3731 | }
|
3732 | |
3733 |
|
3734 |
|
3735 |
|
3736 |
|
3737 |
|
3738 | createQueryParams(redirectToParams, actualParams) {
|
3739 |
|
3740 | const res = {};
|
3741 | forEach(redirectToParams, ( |
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 | (v, k) => {
|
3747 |
|
3748 | const copySourceValue = typeof v === 'string' && v.startsWith(':');
|
3749 | if (copySourceValue) {
|
3750 |
|
3751 | const sourceName = v.substring(1);
|
3752 | res[k] = actualParams[sourceName];
|
3753 | }
|
3754 | else {
|
3755 | res[k] = v;
|
3756 | }
|
3757 | }));
|
3758 | return res;
|
3759 | }
|
3760 | |
3761 |
|
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 | createSegmentGroup(redirectTo, group, segments, posParams) {
|
3769 |
|
3770 | const updatedSegments = this.createSegments(redirectTo, group.segments, segments, posParams);
|
3771 |
|
3772 | let children = {};
|
3773 | forEach(group.children, ( |
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 | (child, name) => {
|
3779 | children[name] = this.createSegmentGroup(redirectTo, child, segments, posParams);
|
3780 | }));
|
3781 | return new UrlSegmentGroup(updatedSegments, children);
|
3782 | }
|
3783 | |
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 | createSegments(redirectTo, redirectToSegments, actualSegments, posParams) {
|
3792 | return redirectToSegments.map(( |
3793 |
|
3794 |
|
3795 |
|
3796 | s => s.path.startsWith(':') ? this.findPosParam(redirectTo, s, posParams) :
|
3797 | this.findOrReturn(s, actualSegments)));
|
3798 | }
|
3799 | |
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 | findPosParam(redirectTo, redirectToUrlSegment, posParams) {
|
3807 |
|
3808 | const pos = posParams[redirectToUrlSegment.path.substring(1)];
|
3809 | if (!pos)
|
3810 | throw new Error(`Cannot redirect to '${redirectTo}'. Cannot find '${redirectToUrlSegment.path}'.`);
|
3811 | return pos;
|
3812 | }
|
3813 | |
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 | findOrReturn(redirectToUrlSegment, actualSegments) {
|
3820 |
|
3821 | let idx = 0;
|
3822 | for (const s of actualSegments) {
|
3823 | if (s.path === redirectToUrlSegment.path) {
|
3824 | actualSegments.splice(idx);
|
3825 | return s;
|
3826 | }
|
3827 | idx++;
|
3828 | }
|
3829 | return redirectToUrlSegment;
|
3830 | }
|
3831 | }
|
3832 |
|
3833 |
|
3834 |
|
3835 |
|
3836 |
|
3837 |
|
3838 | function runCanLoadGuard(moduleInjector, route, segments) {
|
3839 |
|
3840 | const canLoad = route.canLoad;
|
3841 | if (!canLoad || canLoad.length === 0)
|
3842 | return of(true);
|
3843 |
|
3844 | const obs = from(canLoad).pipe(map(( |
3845 |
|
3846 |
|
3847 |
|
3848 | (injectionToken) => {
|
3849 |
|
3850 | const guard = moduleInjector.get(injectionToken);
|
3851 |
|
3852 | let guardVal;
|
3853 | if (isCanLoad(guard)) {
|
3854 | guardVal = guard.canLoad(route, segments);
|
3855 | }
|
3856 | else if (isFunction(guard)) {
|
3857 | guardVal = guard(route, segments);
|
3858 | }
|
3859 | else {
|
3860 | throw new Error('Invalid CanLoad guard');
|
3861 | }
|
3862 | return wrapIntoObservable(guardVal);
|
3863 | })));
|
3864 | return obs.pipe(concatAll(), every(( |
3865 |
|
3866 |
|
3867 |
|
3868 | result => result === true)));
|
3869 | }
|
3870 |
|
3871 |
|
3872 |
|
3873 |
|
3874 |
|
3875 |
|
3876 | function match(segmentGroup, route, segments) {
|
3877 | if (route.path === '') {
|
3878 | if ((route.pathMatch === 'full') && (segmentGroup.hasChildren() || segments.length > 0)) {
|
3879 | return { matched: false, consumedSegments: [], lastChild: 0, positionalParamSegments: {} };
|
3880 | }
|
3881 | return { matched: true, consumedSegments: [], lastChild: 0, positionalParamSegments: {} };
|
3882 | }
|
3883 |
|
3884 | const matcher = route.matcher || defaultUrlMatcher;
|
3885 |
|
3886 | const res = matcher(segments, segmentGroup, route);
|
3887 | if (!res) {
|
3888 | return {
|
3889 | matched: false,
|
3890 | consumedSegments: ( ([])),
|
3891 | lastChild: 0,
|
3892 | positionalParamSegments: {},
|
3893 | };
|
3894 | }
|
3895 | return {
|
3896 | matched: true,
|
3897 | consumedSegments: ( (res.consumed)),
|
3898 | lastChild: ( (res.consumed.length)),
|
3899 | positionalParamSegments: ( (res.posParams)),
|
3900 | };
|
3901 | }
|
3902 |
|
3903 |
|
3904 |
|
3905 |
|
3906 |
|
3907 |
|
3908 |
|
3909 | function split(segmentGroup, consumedSegments, slicedSegments, config) {
|
3910 | if (slicedSegments.length > 0 &&
|
3911 | containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, slicedSegments, config)) {
|
3912 |
|
3913 | const s = new UrlSegmentGroup(consumedSegments, createChildrenForEmptySegments(config, new UrlSegmentGroup(slicedSegments, segmentGroup.children)));
|
3914 | return { segmentGroup: mergeTrivialChildren(s), slicedSegments: [] };
|
3915 | }
|
3916 | if (slicedSegments.length === 0 &&
|
3917 | containsEmptyPathRedirects(segmentGroup, slicedSegments, config)) {
|
3918 |
|
3919 | const s = new UrlSegmentGroup(segmentGroup.segments, addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, config, segmentGroup.children));
|
3920 | return { segmentGroup: mergeTrivialChildren(s), slicedSegments };
|
3921 | }
|
3922 | return { segmentGroup, slicedSegments };
|
3923 | }
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 | function mergeTrivialChildren(s) {
|
3929 | if (s.numberOfChildren === 1 && s.children[PRIMARY_OUTLET]) {
|
3930 |
|
3931 | const c = s.children[PRIMARY_OUTLET];
|
3932 | return new UrlSegmentGroup(s.segments.concat(c.segments), c.children);
|
3933 | }
|
3934 | return s;
|
3935 | }
|
3936 |
|
3937 |
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 |
|
3943 | function addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, routes, children) {
|
3944 |
|
3945 | const res = {};
|
3946 | for (const r of routes) {
|
3947 | if (isEmptyPathRedirect(segmentGroup, slicedSegments, r) && !children[getOutlet(r)]) {
|
3948 | res[getOutlet(r)] = new UrlSegmentGroup([], {});
|
3949 | }
|
3950 | }
|
3951 | return Object.assign({}, children, res);
|
3952 | }
|
3953 |
|
3954 |
|
3955 |
|
3956 |
|
3957 |
|
3958 | function createChildrenForEmptySegments(routes, primarySegmentGroup) {
|
3959 |
|
3960 | const res = {};
|
3961 | res[PRIMARY_OUTLET] = primarySegmentGroup;
|
3962 | for (const r of routes) {
|
3963 | if (r.path === '' && getOutlet(r) !== PRIMARY_OUTLET) {
|
3964 | res[getOutlet(r)] = new UrlSegmentGroup([], {});
|
3965 | }
|
3966 | }
|
3967 | return res;
|
3968 | }
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 | function containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, segments, routes) {
|
3976 | return routes.some(( |
3977 |
|
3978 |
|
3979 |
|
3980 | r => isEmptyPathRedirect(segmentGroup, segments, r) && getOutlet(r) !== PRIMARY_OUTLET));
|
3981 | }
|
3982 |
|
3983 |
|
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 | function containsEmptyPathRedirects(segmentGroup, segments, routes) {
|
3989 | return routes.some(( |
3990 |
|
3991 |
|
3992 |
|
3993 | r => isEmptyPathRedirect(segmentGroup, segments, r)));
|
3994 | }
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 | function isEmptyPathRedirect(segmentGroup, segments, r) {
|
4002 | if ((segmentGroup.hasChildren() || segments.length > 0) && r.pathMatch === 'full') {
|
4003 | return false;
|
4004 | }
|
4005 | return r.path === '' && r.redirectTo !== undefined;
|
4006 | }
|
4007 |
|
4008 |
|
4009 |
|
4010 |
|
4011 | function getOutlet(route) {
|
4012 | return route.outlet || PRIMARY_OUTLET;
|
4013 | }
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 |
|
4024 |
|
4025 |
|
4026 | function applyRedirects$1(moduleInjector, configLoader, urlSerializer, config) {
|
4027 | return ( |
4028 |
|
4029 |
|
4030 |
|
4031 | function (source) {
|
4032 | return source.pipe(switchMap(( |
4033 |
|
4034 |
|
4035 |
|
4036 | t => applyRedirects(moduleInjector, configLoader, urlSerializer, t.extractedUrl, config)
|
4037 | .pipe(map(( |
4038 |
|
4039 |
|
4040 |
|
4041 | urlAfterRedirects => (Object.assign({}, t, { urlAfterRedirects }))))))));
|
4042 | });
|
4043 | }
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 | class CanActivate {
|
4050 | |
4051 |
|
4052 |
|
4053 | constructor(path) {
|
4054 | this.path = path;
|
4055 | this.route = this.path[this.path.length - 1];
|
4056 | }
|
4057 | }
|
4058 | class CanDeactivate {
|
4059 | |
4060 |
|
4061 |
|
4062 |
|
4063 | constructor(component, route) {
|
4064 | this.component = component;
|
4065 | this.route = route;
|
4066 | }
|
4067 | }
|
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 | function getAllRouteGuards(future, curr, parentContexts) {
|
4075 |
|
4076 | const futureRoot = future._root;
|
4077 |
|
4078 | const currRoot = curr ? curr._root : null;
|
4079 | return getChildRouteGuards(futureRoot, currRoot, parentContexts, [futureRoot.value]);
|
4080 | }
|
4081 |
|
4082 |
|
4083 |
|
4084 |
|
4085 | function getCanActivateChild(p) {
|
4086 |
|
4087 | const canActivateChild = p.routeConfig ? p.routeConfig.canActivateChild : null;
|
4088 | if (!canActivateChild || canActivateChild.length === 0)
|
4089 | return null;
|
4090 | return { node: p, guards: canActivateChild };
|
4091 | }
|
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 |
|
4098 | function getToken(token, snapshot, moduleInjector) {
|
4099 |
|
4100 | const config = getClosestLoadedConfig(snapshot);
|
4101 |
|
4102 | const injector = config ? config.module.injector : moduleInjector;
|
4103 | return injector.get(token);
|
4104 | }
|
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 | function getClosestLoadedConfig(snapshot) {
|
4110 | if (!snapshot)
|
4111 | return null;
|
4112 | for (let s = snapshot.parent; s; s = s.parent) {
|
4113 |
|
4114 | const route = s.routeConfig;
|
4115 | if (route && route._loadedConfig)
|
4116 | return route._loadedConfig;
|
4117 | }
|
4118 | return null;
|
4119 | }
|
4120 |
|
4121 |
|
4122 |
|
4123 |
|
4124 |
|
4125 |
|
4126 |
|
4127 |
|
4128 | function getChildRouteGuards(futureNode, currNode, contexts, futurePath, checks = {
|
4129 | canDeactivateChecks: [],
|
4130 | canActivateChecks: []
|
4131 | }) {
|
4132 |
|
4133 | const prevChildren = nodeChildrenAsMap(currNode);
|
4134 |
|
4135 | futureNode.children.forEach(( |
4136 |
|
4137 |
|
4138 |
|
4139 | c => {
|
4140 | getRouteGuards(c, prevChildren[c.value.outlet], contexts, futurePath.concat([c.value]), checks);
|
4141 | delete prevChildren[c.value.outlet];
|
4142 | }));
|
4143 |
|
4144 | forEach(prevChildren, ( |
4145 |
|
4146 |
|
4147 |
|
4148 |
|
4149 | (v, k) => deactivateRouteAndItsChildren(v, ( (contexts)).getContext(k), checks)));
|
4150 | return checks;
|
4151 | }
|
4152 |
|
4153 |
|
4154 |
|
4155 |
|
4156 |
|
4157 |
|
4158 |
|
4159 |
|
4160 | function getRouteGuards(futureNode, currNode, parentContexts, futurePath, checks = {
|
4161 | canDeactivateChecks: [],
|
4162 | canActivateChecks: []
|
4163 | }) {
|
4164 |
|
4165 | const future = futureNode.value;
|
4166 |
|
4167 | const curr = currNode ? currNode.value : null;
|
4168 |
|
4169 | const context = parentContexts ? parentContexts.getContext(futureNode.value.outlet) : null;
|
4170 |
|
4171 | if (curr && future.routeConfig === curr.routeConfig) {
|
4172 |
|
4173 | const shouldRun = shouldRunGuardsAndResolvers(curr, future, ( (future.routeConfig)).runGuardsAndResolvers);
|
4174 | if (shouldRun) {
|
4175 | checks.canActivateChecks.push(new CanActivate(futurePath));
|
4176 | }
|
4177 | else {
|
4178 |
|
4179 | future.data = curr.data;
|
4180 | future._resolvedData = curr._resolvedData;
|
4181 | }
|
4182 |
|
4183 | if (future.component) {
|
4184 | getChildRouteGuards(futureNode, currNode, context ? context.children : null, futurePath, checks);
|
4185 |
|
4186 | }
|
4187 | else {
|
4188 | getChildRouteGuards(futureNode, currNode, parentContexts, futurePath, checks);
|
4189 | }
|
4190 | if (shouldRun) {
|
4191 |
|
4192 | const component = context && context.outlet && context.outlet.component || null;
|
4193 | checks.canDeactivateChecks.push(new CanDeactivate(component, curr));
|
4194 | }
|
4195 | }
|
4196 | else {
|
4197 | if (curr) {
|
4198 | deactivateRouteAndItsChildren(currNode, context, checks);
|
4199 | }
|
4200 | checks.canActivateChecks.push(new CanActivate(futurePath));
|
4201 |
|
4202 | if (future.component) {
|
4203 | getChildRouteGuards(futureNode, null, context ? context.children : null, futurePath, checks);
|
4204 |
|
4205 | }
|
4206 | else {
|
4207 | getChildRouteGuards(futureNode, null, parentContexts, futurePath, checks);
|
4208 | }
|
4209 | }
|
4210 | return checks;
|
4211 | }
|
4212 |
|
4213 |
|
4214 |
|
4215 |
|
4216 |
|
4217 |
|
4218 | function shouldRunGuardsAndResolvers(curr, future, mode) {
|
4219 | if (typeof mode === 'function') {
|
4220 | return mode(curr, future);
|
4221 | }
|
4222 | switch (mode) {
|
4223 | case 'pathParamsChange':
|
4224 | return !equalPath(curr.url, future.url);
|
4225 | case 'pathParamsOrQueryParamsChange':
|
4226 | return !equalPath(curr.url, future.url) ||
|
4227 | !shallowEqual(curr.queryParams, future.queryParams);
|
4228 | case 'always':
|
4229 | return true;
|
4230 | case 'paramsOrQueryParamsChange':
|
4231 | return !equalParamsAndUrlSegments(curr, future) ||
|
4232 | !shallowEqual(curr.queryParams, future.queryParams);
|
4233 | case 'paramsChange':
|
4234 | default:
|
4235 | return !equalParamsAndUrlSegments(curr, future);
|
4236 | }
|
4237 | }
|
4238 |
|
4239 |
|
4240 |
|
4241 |
|
4242 |
|
4243 |
|
4244 | function deactivateRouteAndItsChildren(route, context, checks) {
|
4245 |
|
4246 | const children = nodeChildrenAsMap(route);
|
4247 |
|
4248 | const r = route.value;
|
4249 | forEach(children, ( |
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 | (node, childName) => {
|
4255 | if (!r.component) {
|
4256 | deactivateRouteAndItsChildren(node, context, checks);
|
4257 | }
|
4258 | else if (context) {
|
4259 | deactivateRouteAndItsChildren(node, context.children.getContext(childName), checks);
|
4260 | }
|
4261 | else {
|
4262 | deactivateRouteAndItsChildren(node, null, checks);
|
4263 | }
|
4264 | }));
|
4265 | if (!r.component) {
|
4266 | checks.canDeactivateChecks.push(new CanDeactivate(null, r));
|
4267 | }
|
4268 | else if (context && context.outlet && context.outlet.isActivated) {
|
4269 | checks.canDeactivateChecks.push(new CanDeactivate(context.outlet.component, r));
|
4270 | }
|
4271 | else {
|
4272 | checks.canDeactivateChecks.push(new CanDeactivate(null, r));
|
4273 | }
|
4274 | }
|
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 |
|
4280 |
|
4281 | const INITIAL_VALUE = Symbol('INITIAL_VALUE');
|
4282 |
|
4283 |
|
4284 |
|
4285 | function prioritizedGuardValue() {
|
4286 | return switchMap(( |
4287 |
|
4288 |
|
4289 |
|
4290 | obs => {
|
4291 | return ( (combineLatest(...obs.map(( |
4292 |
|
4293 |
|
4294 |
|
4295 | o => o.pipe(take(1), startWith(( (INITIAL_VALUE)))))))
|
4296 | .pipe(scan(( |
4297 |
|
4298 |
|
4299 |
|
4300 |
|
4301 | (acc, list) => {
|
4302 |
|
4303 | let isPending = false;
|
4304 | return list.reduce(( |
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 |
|
4310 | (innerAcc, val, i) => {
|
4311 | if (innerAcc !== INITIAL_VALUE)
|
4312 | return innerAcc;
|
4313 |
|
4314 | if (val === INITIAL_VALUE)
|
4315 | isPending = true;
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 | if (!isPending) {
|
4321 |
|
4322 |
|
4323 | if (val === false)
|
4324 | return val;
|
4325 | if (i === list.length - 1 || isUrlTree(val)) {
|
4326 | return val;
|
4327 | }
|
4328 | }
|
4329 | return innerAcc;
|
4330 | }), acc);
|
4331 | }), INITIAL_VALUE), filter(( |
4332 |
|
4333 |
|
4334 |
|
4335 | item => item !== INITIAL_VALUE)), map(( |
4336 |
|
4337 |
|
4338 |
|
4339 | item => isUrlTree(item) ? item : item === true)),
|
4340 | take(1))));
|
4341 | }));
|
4342 | }
|
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 |
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 | function checkGuards(moduleInjector, forwardEvent) {
|
4354 | return ( |
4355 |
|
4356 |
|
4357 |
|
4358 | function (source) {
|
4359 | return source.pipe(mergeMap(( |
4360 |
|
4361 |
|
4362 |
|
4363 | t => {
|
4364 | const { targetSnapshot, currentSnapshot, guards: { canActivateChecks, canDeactivateChecks } } = t;
|
4365 | if (canDeactivateChecks.length === 0 && canActivateChecks.length === 0) {
|
4366 | return of(Object.assign({}, t, { guardsResult: true }));
|
4367 | }
|
4368 | return runCanDeactivateChecks(canDeactivateChecks, ( (targetSnapshot)), currentSnapshot, moduleInjector)
|
4369 | .pipe(mergeMap(( |
4370 |
|
4371 |
|
4372 |
|
4373 | canDeactivate => {
|
4374 | return canDeactivate && isBoolean(canDeactivate) ?
|
4375 | runCanActivateChecks(( (targetSnapshot)), canActivateChecks, moduleInjector, forwardEvent) :
|
4376 | of(canDeactivate);
|
4377 | })), map(( |
4378 |
|
4379 |
|
4380 |
|
4381 | guardsResult => (Object.assign({}, t, { guardsResult })))));
|
4382 | })));
|
4383 | });
|
4384 | }
|
4385 |
|
4386 |
|
4387 |
|
4388 |
|
4389 |
|
4390 |
|
4391 |
|
4392 | function runCanDeactivateChecks(checks, futureRSS, currRSS, moduleInjector) {
|
4393 | return from(checks).pipe(mergeMap(( |
4394 |
|
4395 |
|
4396 |
|
4397 | check => runCanDeactivate(check.component, check.route, currRSS, futureRSS, moduleInjector))), first(( |
4398 |
|
4399 |
|
4400 |
|
4401 | result => { return result !== true; }), ( (true))));
|
4402 | }
|
4403 |
|
4404 |
|
4405 |
|
4406 |
|
4407 |
|
4408 |
|
4409 |
|
4410 | function runCanActivateChecks(futureSnapshot, checks, moduleInjector, forwardEvent) {
|
4411 | return from(checks).pipe(concatMap(( |
4412 |
|
4413 |
|
4414 |
|
4415 | (check) => {
|
4416 | return from([
|
4417 | fireChildActivationStart(check.route.parent, forwardEvent),
|
4418 | fireActivationStart(check.route, forwardEvent),
|
4419 | runCanActivateChild(futureSnapshot, check.path, moduleInjector),
|
4420 | runCanActivate(futureSnapshot, check.route, moduleInjector)
|
4421 | ])
|
4422 | .pipe(concatAll(), first(( |
4423 |
|
4424 |
|
4425 |
|
4426 | result => {
|
4427 | return result !== true;
|
4428 | }), ( (true))));
|
4429 | })), first(( |
4430 |
|
4431 |
|
4432 |
|
4433 | result => { return result !== true; }), ( (true))));
|
4434 | }
|
4435 |
|
4436 |
|
4437 |
|
4438 |
|
4439 |
|
4440 |
|
4441 |
|
4442 |
|
4443 |
|
4444 |
|
4445 |
|
4446 | function fireActivationStart(snapshot, forwardEvent) {
|
4447 | if (snapshot !== null && forwardEvent) {
|
4448 | forwardEvent(new ActivationStart(snapshot));
|
4449 | }
|
4450 | return of(true);
|
4451 | }
|
4452 |
|
4453 |
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 | function fireChildActivationStart(snapshot, forwardEvent) {
|
4464 | if (snapshot !== null && forwardEvent) {
|
4465 | forwardEvent(new ChildActivationStart(snapshot));
|
4466 | }
|
4467 | return of(true);
|
4468 | }
|
4469 |
|
4470 |
|
4471 |
|
4472 |
|
4473 |
|
4474 |
|
4475 | function runCanActivate(futureRSS, futureARS, moduleInjector) {
|
4476 |
|
4477 | const canActivate = futureARS.routeConfig ? futureARS.routeConfig.canActivate : null;
|
4478 | if (!canActivate || canActivate.length === 0)
|
4479 | return of(true);
|
4480 |
|
4481 | const canActivateObservables = canActivate.map(( |
4482 |
|
4483 |
|
4484 |
|
4485 | (c) => {
|
4486 | return defer(( |
4487 |
|
4488 |
|
4489 | () => {
|
4490 |
|
4491 | const guard = getToken(c, futureARS, moduleInjector);
|
4492 |
|
4493 | let observable;
|
4494 | if (isCanActivate(guard)) {
|
4495 | observable = wrapIntoObservable(guard.canActivate(futureARS, futureRSS));
|
4496 | }
|
4497 | else if (isFunction(guard)) {
|
4498 | observable = wrapIntoObservable(guard(futureARS, futureRSS));
|
4499 | }
|
4500 | else {
|
4501 | throw new Error('Invalid CanActivate guard');
|
4502 | }
|
4503 | return observable.pipe(first());
|
4504 | }));
|
4505 | }));
|
4506 | return of(canActivateObservables).pipe(prioritizedGuardValue());
|
4507 | }
|
4508 |
|
4509 |
|
4510 |
|
4511 |
|
4512 |
|
4513 |
|
4514 | function runCanActivateChild(futureRSS, path, moduleInjector) {
|
4515 |
|
4516 | const futureARS = path[path.length - 1];
|
4517 |
|
4518 | const canActivateChildGuards = path.slice(0, path.length - 1)
|
4519 | .reverse()
|
4520 | .map(( |
4521 |
|
4522 |
|
4523 |
|
4524 | p => getCanActivateChild(p)))
|
4525 | .filter(( |
4526 |
|
4527 |
|
4528 |
|
4529 | _ => _ !== null));
|
4530 |
|
4531 | const canActivateChildGuardsMapped = canActivateChildGuards.map(( |
4532 |
|
4533 |
|
4534 |
|
4535 | (d) => {
|
4536 | return defer(( |
4537 |
|
4538 |
|
4539 | () => {
|
4540 |
|
4541 | const guardsMapped = d.guards.map(( |
4542 |
|
4543 |
|
4544 |
|
4545 | (c) => {
|
4546 |
|
4547 | const guard = getToken(c, d.node, moduleInjector);
|
4548 |
|
4549 | let observable;
|
4550 | if (isCanActivateChild(guard)) {
|
4551 | observable = wrapIntoObservable(guard.canActivateChild(futureARS, futureRSS));
|
4552 | }
|
4553 | else if (isFunction(guard)) {
|
4554 | observable = wrapIntoObservable(guard(futureARS, futureRSS));
|
4555 | }
|
4556 | else {
|
4557 | throw new Error('Invalid CanActivateChild guard');
|
4558 | }
|
4559 | return observable.pipe(first());
|
4560 | }));
|
4561 | return of(guardsMapped).pipe(prioritizedGuardValue());
|
4562 | }));
|
4563 | }));
|
4564 | return of(canActivateChildGuardsMapped).pipe(prioritizedGuardValue());
|
4565 | }
|
4566 |
|
4567 |
|
4568 |
|
4569 |
|
4570 |
|
4571 |
|
4572 |
|
4573 |
|
4574 | function runCanDeactivate(component, currARS, currRSS, futureRSS, moduleInjector) {
|
4575 |
|
4576 | const canDeactivate = currARS && currARS.routeConfig ? currARS.routeConfig.canDeactivate : null;
|
4577 | if (!canDeactivate || canDeactivate.length === 0)
|
4578 | return of(true);
|
4579 |
|
4580 | const canDeactivateObservables = canDeactivate.map(( |
4581 |
|
4582 |
|
4583 |
|
4584 | (c) => {
|
4585 |
|
4586 | const guard = getToken(c, currARS, moduleInjector);
|
4587 |
|
4588 | let observable;
|
4589 | if (isCanDeactivate(guard)) {
|
4590 | observable =
|
4591 | wrapIntoObservable(guard.canDeactivate(( (component)), currARS, currRSS, futureRSS));
|
4592 | }
|
4593 | else if (isFunction(guard)) {
|
4594 | observable = wrapIntoObservable(guard(component, currARS, currRSS, futureRSS));
|
4595 | }
|
4596 | else {
|
4597 | throw new Error('Invalid CanDeactivate guard');
|
4598 | }
|
4599 | return observable.pipe(first());
|
4600 | }));
|
4601 | return of(canDeactivateObservables).pipe(prioritizedGuardValue());
|
4602 | }
|
4603 |
|
4604 |
|
4605 |
|
4606 |
|
4607 |
|
4608 | class NoMatch$1 {
|
4609 | }
|
4610 |
|
4611 |
|
4612 |
|
4613 |
|
4614 |
|
4615 |
|
4616 |
|
4617 |
|
4618 |
|
4619 | function recognize(rootComponentType, config, urlTree, url, paramsInheritanceStrategy = 'emptyOnly', relativeLinkResolution = 'legacy') {
|
4620 | return new Recognizer(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution)
|
4621 | .recognize();
|
4622 | }
|
4623 | class Recognizer {
|
4624 | |
4625 |
|
4626 |
|
4627 |
|
4628 |
|
4629 |
|
4630 |
|
4631 |
|
4632 | constructor(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution) {
|
4633 | this.rootComponentType = rootComponentType;
|
4634 | this.config = config;
|
4635 | this.urlTree = urlTree;
|
4636 | this.url = url;
|
4637 | this.paramsInheritanceStrategy = paramsInheritanceStrategy;
|
4638 | this.relativeLinkResolution = relativeLinkResolution;
|
4639 | }
|
4640 | |
4641 |
|
4642 |
|
4643 | recognize() {
|
4644 | try {
|
4645 |
|
4646 | const rootSegmentGroup = split$1(this.urlTree.root, [], [], this.config, this.relativeLinkResolution).segmentGroup;
|
4647 |
|
4648 | const children = this.processSegmentGroup(this.config, rootSegmentGroup, PRIMARY_OUTLET);
|
4649 |
|
4650 | const root = new ActivatedRouteSnapshot([], Object.freeze({}), Object.freeze(Object.assign({}, this.urlTree.queryParams)), ( (this.urlTree.fragment)), {}, PRIMARY_OUTLET, this.rootComponentType, null, this.urlTree.root, -1, {});
|
4651 |
|
4652 | const rootNode = new TreeNode(root, children);
|
4653 |
|
4654 | const routeState = new RouterStateSnapshot(this.url, rootNode);
|
4655 | this.inheritParamsAndData(routeState._root);
|
4656 | return of(routeState);
|
4657 | }
|
4658 | catch (e) {
|
4659 | return new Observable(( |
4660 |
|
4661 |
|
4662 |
|
4663 | (obs) => obs.error(e)));
|
4664 | }
|
4665 | }
|
4666 | |
4667 |
|
4668 |
|
4669 |
|
4670 | inheritParamsAndData(routeNode) {
|
4671 |
|
4672 | const route = routeNode.value;
|
4673 |
|
4674 | const i = inheritedParamsDataResolve(route, this.paramsInheritanceStrategy);
|
4675 | route.params = Object.freeze(i.params);
|
4676 | route.data = Object.freeze(i.data);
|
4677 | routeNode.children.forEach(( |
4678 |
|
4679 |
|
4680 |
|
4681 | n => this.inheritParamsAndData(n)));
|
4682 | }
|
4683 | |
4684 |
|
4685 |
|
4686 |
|
4687 |
|
4688 |
|
4689 | processSegmentGroup(config, segmentGroup, outlet) {
|
4690 | if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
|
4691 | return this.processChildren(config, segmentGroup);
|
4692 | }
|
4693 | return this.processSegment(config, segmentGroup, segmentGroup.segments, outlet);
|
4694 | }
|
4695 | |
4696 |
|
4697 |
|
4698 |
|
4699 |
|
4700 | processChildren(config, segmentGroup) {
|
4701 |
|
4702 | const children = mapChildrenIntoArray(segmentGroup, ( |
4703 |
|
4704 |
|
4705 |
|
4706 |
|
4707 | (child, childOutlet) => this.processSegmentGroup(config, child, childOutlet)));
|
4708 | checkOutletNameUniqueness(children);
|
4709 | sortActivatedRouteSnapshots(children);
|
4710 | return children;
|
4711 | }
|
4712 | |
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 | processSegment(config, segmentGroup, segments, outlet) {
|
4720 | for (const r of config) {
|
4721 | try {
|
4722 | return this.processSegmentAgainstRoute(r, segmentGroup, segments, outlet);
|
4723 | }
|
4724 | catch (e) {
|
4725 | if (!(e instanceof NoMatch$1))
|
4726 | throw e;
|
4727 | }
|
4728 | }
|
4729 | if (this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
|
4730 | return [];
|
4731 | }
|
4732 | throw new NoMatch$1();
|
4733 | }
|
4734 | |
4735 |
|
4736 |
|
4737 |
|
4738 |
|
4739 |
|
4740 |
|
4741 | noLeftoversInUrl(segmentGroup, segments, outlet) {
|
4742 | return segments.length === 0 && !segmentGroup.children[outlet];
|
4743 | }
|
4744 | |
4745 |
|
4746 |
|
4747 |
|
4748 |
|
4749 |
|
4750 |
|
4751 | processSegmentAgainstRoute(route, rawSegment, segments, outlet) {
|
4752 | if (route.redirectTo)
|
4753 | throw new NoMatch$1();
|
4754 | if ((route.outlet || PRIMARY_OUTLET) !== outlet)
|
4755 | throw new NoMatch$1();
|
4756 |
|
4757 | let snapshot;
|
4758 |
|
4759 | let consumedSegments = [];
|
4760 |
|
4761 | let rawSlicedSegments = [];
|
4762 | if (route.path === '**') {
|
4763 |
|
4764 | const params = segments.length > 0 ? ( (last(segments))).parameters : {};
|
4765 | snapshot = new ActivatedRouteSnapshot(segments, params, Object.freeze(Object.assign({}, this.urlTree.queryParams)), ( (this.urlTree.fragment)), getData(route), outlet, ( (route.component)), route, getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + segments.length, getResolve(route));
|
4766 | }
|
4767 | else {
|
4768 |
|
4769 | const result = match$1(rawSegment, route, segments);
|
4770 | consumedSegments = result.consumedSegments;
|
4771 | rawSlicedSegments = segments.slice(result.lastChild);
|
4772 | snapshot = new ActivatedRouteSnapshot(consumedSegments, result.parameters, Object.freeze(Object.assign({}, this.urlTree.queryParams)), ( (this.urlTree.fragment)), getData(route), outlet, ( (route.component)), route, getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + consumedSegments.length, getResolve(route));
|
4773 | }
|
4774 |
|
4775 | const childConfig = getChildConfig(route);
|
4776 | const { segmentGroup, slicedSegments } = split$1(rawSegment, consumedSegments, rawSlicedSegments, childConfig, this.relativeLinkResolution);
|
4777 | if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
|
4778 |
|
4779 | const children = this.processChildren(childConfig, segmentGroup);
|
4780 | return [new TreeNode(snapshot, children)];
|
4781 | }
|
4782 | if (childConfig.length === 0 && slicedSegments.length === 0) {
|
4783 | return [new TreeNode(snapshot, [])];
|
4784 | }
|
4785 |
|
4786 | const children = this.processSegment(childConfig, segmentGroup, slicedSegments, PRIMARY_OUTLET);
|
4787 | return [new TreeNode(snapshot, children)];
|
4788 | }
|
4789 | }
|
4790 |
|
4791 |
|
4792 |
|
4793 |
|
4794 | function sortActivatedRouteSnapshots(nodes) {
|
4795 | nodes.sort(( |
4796 |
|
4797 |
|
4798 |
|
4799 |
|
4800 | (a, b) => {
|
4801 | if (a.value.outlet === PRIMARY_OUTLET)
|
4802 | return -1;
|
4803 | if (b.value.outlet === PRIMARY_OUTLET)
|
4804 | return 1;
|
4805 | return a.value.outlet.localeCompare(b.value.outlet);
|
4806 | }));
|
4807 | }
|
4808 |
|
4809 |
|
4810 |
|
4811 |
|
4812 | function getChildConfig(route) {
|
4813 | if (route.children) {
|
4814 | return route.children;
|
4815 | }
|
4816 | if (route.loadChildren) {
|
4817 | return ( (route._loadedConfig)).routes;
|
4818 | }
|
4819 | return [];
|
4820 | }
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 | function match$1(segmentGroup, route, segments) {
|
4828 | if (route.path === '') {
|
4829 | if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || segments.length > 0)) {
|
4830 | throw new NoMatch$1();
|
4831 | }
|
4832 | return { consumedSegments: [], lastChild: 0, parameters: {} };
|
4833 | }
|
4834 |
|
4835 | const matcher = route.matcher || defaultUrlMatcher;
|
4836 |
|
4837 | const res = matcher(segments, segmentGroup, route);
|
4838 | if (!res)
|
4839 | throw new NoMatch$1();
|
4840 |
|
4841 | const posParams = {};
|
4842 | forEach(( (res.posParams)), ( |
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 | (v, k) => { posParams[k] = v.path; }));
|
4848 |
|
4849 | const parameters = res.consumed.length > 0 ? Object.assign({}, posParams, res.consumed[res.consumed.length - 1].parameters) :
|
4850 | posParams;
|
4851 | return { consumedSegments: res.consumed, lastChild: res.consumed.length, parameters };
|
4852 | }
|
4853 |
|
4854 |
|
4855 |
|
4856 |
|
4857 | function checkOutletNameUniqueness(nodes) {
|
4858 |
|
4859 | const names = {};
|
4860 | nodes.forEach(( |
4861 |
|
4862 |
|
4863 |
|
4864 | n => {
|
4865 |
|
4866 | const routeWithSameOutletName = names[n.value.outlet];
|
4867 | if (routeWithSameOutletName) {
|
4868 |
|
4869 | const p = routeWithSameOutletName.url.map(( |
4870 |
|
4871 |
|
4872 |
|
4873 | s => s.toString())).join('/');
|
4874 |
|
4875 | const c = n.value.url.map(( |
4876 |
|
4877 |
|
4878 |
|
4879 | s => s.toString())).join('/');
|
4880 | throw new Error(`Two segments cannot have the same outlet name: '${p}' and '${c}'.`);
|
4881 | }
|
4882 | names[n.value.outlet] = n.value;
|
4883 | }));
|
4884 | }
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 | function getSourceSegmentGroup(segmentGroup) {
|
4890 |
|
4891 | let s = segmentGroup;
|
4892 | while (s._sourceSegment) {
|
4893 | s = s._sourceSegment;
|
4894 | }
|
4895 | return s;
|
4896 | }
|
4897 |
|
4898 |
|
4899 |
|
4900 |
|
4901 | function getPathIndexShift(segmentGroup) {
|
4902 |
|
4903 | let s = segmentGroup;
|
4904 |
|
4905 | let res = (s._segmentIndexShift ? s._segmentIndexShift : 0);
|
4906 | while (s._sourceSegment) {
|
4907 | s = s._sourceSegment;
|
4908 | res += (s._segmentIndexShift ? s._segmentIndexShift : 0);
|
4909 | }
|
4910 | return res - 1;
|
4911 | }
|
4912 |
|
4913 |
|
4914 |
|
4915 |
|
4916 |
|
4917 |
|
4918 |
|
4919 |
|
4920 | function split$1(segmentGroup, consumedSegments, slicedSegments, config, relativeLinkResolution) {
|
4921 | if (slicedSegments.length > 0 &&
|
4922 | containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, config)) {
|
4923 |
|
4924 | const s = new UrlSegmentGroup(consumedSegments, createChildrenForEmptyPaths(segmentGroup, consumedSegments, config, new UrlSegmentGroup(slicedSegments, segmentGroup.children)));
|
4925 | s._sourceSegment = segmentGroup;
|
4926 | s._segmentIndexShift = consumedSegments.length;
|
4927 | return { segmentGroup: s, slicedSegments: [] };
|
4928 | }
|
4929 | if (slicedSegments.length === 0 &&
|
4930 | containsEmptyPathMatches(segmentGroup, slicedSegments, config)) {
|
4931 |
|
4932 | const s = new UrlSegmentGroup(segmentGroup.segments, addEmptyPathsToChildrenIfNeeded(segmentGroup, consumedSegments, slicedSegments, config, segmentGroup.children, relativeLinkResolution));
|
4933 | s._sourceSegment = segmentGroup;
|
4934 | s._segmentIndexShift = consumedSegments.length;
|
4935 | return { segmentGroup: s, slicedSegments };
|
4936 | }
|
4937 |
|
4938 | const s = new UrlSegmentGroup(segmentGroup.segments, segmentGroup.children);
|
4939 | s._sourceSegment = segmentGroup;
|
4940 | s._segmentIndexShift = consumedSegments.length;
|
4941 | return { segmentGroup: s, slicedSegments };
|
4942 | }
|
4943 |
|
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 | function addEmptyPathsToChildrenIfNeeded(segmentGroup, consumedSegments, slicedSegments, routes, children, relativeLinkResolution) {
|
4953 |
|
4954 | const res = {};
|
4955 | for (const r of routes) {
|
4956 | if (emptyPathMatch(segmentGroup, slicedSegments, r) && !children[getOutlet$1(r)]) {
|
4957 |
|
4958 | const s = new UrlSegmentGroup([], {});
|
4959 | s._sourceSegment = segmentGroup;
|
4960 | if (relativeLinkResolution === 'legacy') {
|
4961 | s._segmentIndexShift = segmentGroup.segments.length;
|
4962 | }
|
4963 | else {
|
4964 | s._segmentIndexShift = consumedSegments.length;
|
4965 | }
|
4966 | res[getOutlet$1(r)] = s;
|
4967 | }
|
4968 | }
|
4969 | return Object.assign({}, children, res);
|
4970 | }
|
4971 |
|
4972 |
|
4973 |
|
4974 |
|
4975 |
|
4976 |
|
4977 |
|
4978 | function createChildrenForEmptyPaths(segmentGroup, consumedSegments, routes, primarySegment) {
|
4979 |
|
4980 | const res = {};
|
4981 | res[PRIMARY_OUTLET] = primarySegment;
|
4982 | primarySegment._sourceSegment = segmentGroup;
|
4983 | primarySegment._segmentIndexShift = consumedSegments.length;
|
4984 | for (const r of routes) {
|
4985 | if (r.path === '' && getOutlet$1(r) !== PRIMARY_OUTLET) {
|
4986 |
|
4987 | const s = new UrlSegmentGroup([], {});
|
4988 | s._sourceSegment = segmentGroup;
|
4989 | s._segmentIndexShift = consumedSegments.length;
|
4990 | res[getOutlet$1(r)] = s;
|
4991 | }
|
4992 | }
|
4993 | return res;
|
4994 | }
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 | function containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, routes) {
|
5002 | return routes.some(( |
5003 |
|
5004 |
|
5005 |
|
5006 | r => emptyPathMatch(segmentGroup, slicedSegments, r) && getOutlet$1(r) !== PRIMARY_OUTLET));
|
5007 | }
|
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 |
|
5013 |
|
5014 | function containsEmptyPathMatches(segmentGroup, slicedSegments, routes) {
|
5015 | return routes.some(( |
5016 |
|
5017 |
|
5018 |
|
5019 | r => emptyPathMatch(segmentGroup, slicedSegments, r)));
|
5020 | }
|
5021 |
|
5022 |
|
5023 |
|
5024 |
|
5025 |
|
5026 |
|
5027 | function emptyPathMatch(segmentGroup, slicedSegments, r) {
|
5028 | if ((segmentGroup.hasChildren() || slicedSegments.length > 0) && r.pathMatch === 'full') {
|
5029 | return false;
|
5030 | }
|
5031 | return r.path === '' && r.redirectTo === undefined;
|
5032 | }
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 | function getOutlet$1(route) {
|
5038 | return route.outlet || PRIMARY_OUTLET;
|
5039 | }
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 | function getData(route) {
|
5045 | return route.data || {};
|
5046 | }
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 | function getResolve(route) {
|
5052 | return route.resolve || {};
|
5053 | }
|
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 | function recognize$1(rootComponentType, config, serializer, paramsInheritanceStrategy, relativeLinkResolution) {
|
5068 | return ( |
5069 |
|
5070 |
|
5071 |
|
5072 | function (source) {
|
5073 | return source.pipe(mergeMap(( |
5074 |
|
5075 |
|
5076 |
|
5077 | t => recognize(rootComponentType, config, t.urlAfterRedirects, serializer(t.urlAfterRedirects), paramsInheritanceStrategy, relativeLinkResolution)
|
5078 | .pipe(map(( |
5079 |
|
5080 |
|
5081 |
|
5082 | targetSnapshot => (Object.assign({}, t, { targetSnapshot }))))))));
|
5083 | });
|
5084 | }
|
5085 |
|
5086 |
|
5087 |
|
5088 |
|
5089 |
|
5090 |
|
5091 |
|
5092 |
|
5093 |
|
5094 |
|
5095 | function resolveData(paramsInheritanceStrategy, moduleInjector) {
|
5096 | return ( |
5097 |
|
5098 |
|
5099 |
|
5100 | function (source) {
|
5101 | return source.pipe(mergeMap(( |
5102 |
|
5103 |
|
5104 |
|
5105 | t => {
|
5106 | const { targetSnapshot, guards: { canActivateChecks } } = t;
|
5107 | if (!canActivateChecks.length) {
|
5108 | return of(t);
|
5109 | }
|
5110 | return from(canActivateChecks)
|
5111 | .pipe(concatMap(( |
5112 |
|
5113 |
|
5114 |
|
5115 | check => runResolve(check.route, ( (targetSnapshot)), paramsInheritanceStrategy, moduleInjector))), reduce(( |
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 | (_, __) => _)), map(( |
5121 |
|
5122 |
|
5123 |
|
5124 | _ => t)));
|
5125 | })));
|
5126 | });
|
5127 | }
|
5128 |
|
5129 |
|
5130 |
|
5131 |
|
5132 |
|
5133 |
|
5134 |
|
5135 | function runResolve(futureARS, futureRSS, paramsInheritanceStrategy, moduleInjector) {
|
5136 |
|
5137 | const resolve = futureARS._resolve;
|
5138 | return resolveNode(resolve, futureARS, futureRSS, moduleInjector)
|
5139 | .pipe(map(( |
5140 |
|
5141 |
|
5142 |
|
5143 | (resolvedData) => {
|
5144 | futureARS._resolvedData = resolvedData;
|
5145 | futureARS.data = Object.assign({}, futureARS.data, inheritedParamsDataResolve(futureARS, paramsInheritanceStrategy).resolve);
|
5146 | return null;
|
5147 | })));
|
5148 | }
|
5149 |
|
5150 |
|
5151 |
|
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 | function resolveNode(resolve, futureARS, futureRSS, moduleInjector) {
|
5157 |
|
5158 | const keys = Object.keys(resolve);
|
5159 | if (keys.length === 0) {
|
5160 | return of({});
|
5161 | }
|
5162 | if (keys.length === 1) {
|
5163 |
|
5164 | const key = keys[0];
|
5165 | return getResolver(resolve[key], futureARS, futureRSS, moduleInjector)
|
5166 | .pipe(map(( |
5167 |
|
5168 |
|
5169 |
|
5170 | (value) => { return { [key]: value }; })));
|
5171 | }
|
5172 |
|
5173 | const data = {};
|
5174 |
|
5175 | const runningResolvers$ = from(keys).pipe(mergeMap(( |
5176 |
|
5177 |
|
5178 |
|
5179 | (key) => {
|
5180 | return getResolver(resolve[key], futureARS, futureRSS, moduleInjector)
|
5181 | .pipe(map(( |
5182 |
|
5183 |
|
5184 |
|
5185 | (value) => {
|
5186 | data[key] = value;
|
5187 | return value;
|
5188 | })));
|
5189 | })));
|
5190 | return runningResolvers$.pipe(last$1(), map(( |
5191 |
|
5192 |
|
5193 | () => data)));
|
5194 | }
|
5195 |
|
5196 |
|
5197 |
|
5198 |
|
5199 |
|
5200 |
|
5201 |
|
5202 | function getResolver(injectionToken, futureARS, futureRSS, moduleInjector) {
|
5203 |
|
5204 | const resolver = getToken(injectionToken, futureARS, moduleInjector);
|
5205 | return resolver.resolve ? wrapIntoObservable(resolver.resolve(futureARS, futureRSS)) :
|
5206 | wrapIntoObservable(resolver(futureARS, futureRSS));
|
5207 | }
|
5208 |
|
5209 |
|
5210 |
|
5211 |
|
5212 |
|
5213 |
|
5214 |
|
5215 |
|
5216 |
|
5217 |
|
5218 |
|
5219 |
|
5220 |
|
5221 |
|
5222 | function switchTap(next) {
|
5223 | return ( |
5224 |
|
5225 |
|
5226 |
|
5227 | function (source) {
|
5228 | return source.pipe(switchMap(( |
5229 |
|
5230 |
|
5231 |
|
5232 | v => {
|
5233 |
|
5234 | const nextResult = next(v);
|
5235 | if (nextResult) {
|
5236 | return from(nextResult).pipe(map(( |
5237 |
|
5238 |
|
5239 | () => v)));
|
5240 | }
|
5241 | return from([v]);
|
5242 | })));
|
5243 | });
|
5244 | }
|
5245 |
|
5246 |
|
5247 |
|
5248 |
|
5249 |
|
5250 |
|
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 |
|
5265 | class RouteReuseStrategy {
|
5266 | }
|
5267 |
|
5268 |
|
5269 |
|
5270 | class DefaultRouteReuseStrategy {
|
5271 | |
5272 |
|
5273 |
|
5274 |
|
5275 | shouldDetach(route) { return false; }
|
5276 | |
5277 |
|
5278 |
|
5279 |
|
5280 |
|
5281 | store(route, detachedTree) { }
|
5282 | |
5283 |
|
5284 |
|
5285 |
|
5286 | shouldAttach(route) { return false; }
|
5287 | |
5288 |
|
5289 |
|
5290 |
|
5291 | retrieve(route) { return null; }
|
5292 | |
5293 |
|
5294 |
|
5295 |
|
5296 |
|
5297 | shouldReuseRoute(future, curr) {
|
5298 | return future.routeConfig === curr.routeConfig;
|
5299 | }
|
5300 | }
|
5301 |
|
5302 |
|
5303 |
|
5304 |
|
5305 |
|
5306 |
|
5307 |
|
5308 |
|
5309 |
|
5310 |
|
5311 |
|
5312 | const ROUTES = new InjectionToken('ROUTES');
|
5313 | class RouterConfigLoader {
|
5314 | |
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 | constructor(loader, compiler, onLoadStartListener, onLoadEndListener) {
|
5321 | this.loader = loader;
|
5322 | this.compiler = compiler;
|
5323 | this.onLoadStartListener = onLoadStartListener;
|
5324 | this.onLoadEndListener = onLoadEndListener;
|
5325 | }
|
5326 | |
5327 |
|
5328 |
|
5329 |
|
5330 |
|
5331 | load(parentInjector, route) {
|
5332 | if (this.onLoadStartListener) {
|
5333 | this.onLoadStartListener(route);
|
5334 | }
|
5335 |
|
5336 | const moduleFactory$ = this.loadModuleFactory(( (route.loadChildren)));
|
5337 | return moduleFactory$.pipe(map(( |
5338 |
|
5339 |
|
5340 |
|
5341 | (factory) => {
|
5342 | if (this.onLoadEndListener) {
|
5343 | this.onLoadEndListener(route);
|
5344 | }
|
5345 |
|
5346 | const module = factory.create(parentInjector);
|
5347 | return new LoadedRouterConfig(flatten(module.injector.get(ROUTES)).map(standardizeConfig), module);
|
5348 | })));
|
5349 | }
|
5350 | |
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 | loadModuleFactory(loadChildren) {
|
5356 | if (typeof loadChildren === 'string') {
|
5357 | return from(this.loader.load(loadChildren));
|
5358 | }
|
5359 | else {
|
5360 | return wrapIntoObservable(loadChildren()).pipe(mergeMap(( |
5361 |
|
5362 |
|
5363 |
|
5364 | (t) => {
|
5365 | if (t instanceof NgModuleFactory) {
|
5366 | return of(t);
|
5367 | }
|
5368 | else {
|
5369 | return from(this.compiler.compileModuleAsync(t));
|
5370 | }
|
5371 | })));
|
5372 | }
|
5373 | }
|
5374 | }
|
5375 |
|
5376 |
|
5377 |
|
5378 |
|
5379 |
|
5380 |
|
5381 |
|
5382 |
|
5383 |
|
5384 |
|
5385 |
|
5386 |
|
5387 |
|
5388 |
|
5389 |
|
5390 |
|
5391 |
|
5392 |
|
5393 |
|
5394 |
|
5395 | class UrlHandlingStrategy {
|
5396 | }
|
5397 |
|
5398 |
|
5399 |
|
5400 | class DefaultUrlHandlingStrategy {
|
5401 | |
5402 |
|
5403 |
|
5404 |
|
5405 | shouldProcessUrl(url) { return true; }
|
5406 | |
5407 |
|
5408 |
|
5409 |
|
5410 | extract(url) { return url; }
|
5411 | |
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 | merge(newUrlPart, wholeUrl) { return newUrlPart; }
|
5417 | }
|
5418 |
|
5419 |
|
5420 |
|
5421 |
|
5422 |
|
5423 |
|
5424 |
|
5425 |
|
5426 |
|
5427 | function defaultErrorHandler(error) {
|
5428 | throw error;
|
5429 | }
|
5430 |
|
5431 |
|
5432 |
|
5433 |
|
5434 |
|
5435 |
|
5436 | function defaultMalformedUriErrorHandler(error, urlSerializer, url) {
|
5437 | return urlSerializer.parse('/');
|
5438 | }
|
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 | function defaultRouterHook(snapshot, runExtras) {
|
5446 | return ( (of(null)));
|
5447 | }
|
5448 |
|
5449 |
|
5450 |
|
5451 |
|
5452 |
|
5453 |
|
5454 |
|
5455 |
|
5456 |
|
5457 |
|
5458 |
|
5459 |
|
5460 | class Router {
|
5461 | |
5462 |
|
5463 |
|
5464 |
|
5465 |
|
5466 |
|
5467 |
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 |
|
5473 | constructor(rootComponentType, urlSerializer, rootContexts, location, injector, loader, compiler, config) {
|
5474 | this.rootComponentType = rootComponentType;
|
5475 | this.urlSerializer = urlSerializer;
|
5476 | this.rootContexts = rootContexts;
|
5477 | this.location = location;
|
5478 | this.config = config;
|
5479 | this.lastSuccessfulNavigation = null;
|
5480 | this.currentNavigation = null;
|
5481 | this.navigationId = 0;
|
5482 | this.isNgZoneEnabled = false;
|
5483 | |
5484 |
|
5485 |
|
5486 | this.events = new Subject();
|
5487 | |
5488 |
|
5489 |
|
5490 | this.errorHandler = defaultErrorHandler;
|
5491 | |
5492 |
|
5493 |
|
5494 |
|
5495 |
|
5496 |
|
5497 | this.malformedUriErrorHandler = defaultMalformedUriErrorHandler;
|
5498 | |
5499 |
|
5500 |
|
5501 |
|
5502 | this.navigated = false;
|
5503 | this.lastSuccessfulId = -1;
|
5504 | |
5505 |
|
5506 |
|
5507 |
|
5508 |
|
5509 |
|
5510 |
|
5511 | this.hooks = {
|
5512 | beforePreactivation: defaultRouterHook,
|
5513 | afterPreactivation: defaultRouterHook
|
5514 | };
|
5515 | |
5516 |
|
5517 |
|
5518 |
|
5519 | this.urlHandlingStrategy = new DefaultUrlHandlingStrategy();
|
5520 | |
5521 |
|
5522 |
|
5523 | this.routeReuseStrategy = new DefaultRouteReuseStrategy();
|
5524 | |
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 | this.onSameUrlNavigation = 'ignore';
|
5530 | |
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 |
|
5539 | this.paramsInheritanceStrategy = 'emptyOnly';
|
5540 | |
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 | this.urlUpdateStrategy = 'deferred';
|
5548 | |
5549 |
|
5550 |
|
5551 |
|
5552 | this.relativeLinkResolution = 'legacy';
|
5553 |
|
5554 | const onLoadStart = ( |
5555 |
|
5556 |
|
5557 |
|
5558 | (r) => this.triggerEvent(new RouteConfigLoadStart(r)));
|
5559 |
|
5560 | const onLoadEnd = ( |
5561 |
|
5562 |
|
5563 |
|
5564 | (r) => this.triggerEvent(new RouteConfigLoadEnd(r)));
|
5565 | this.ngModule = injector.get(NgModuleRef);
|
5566 | this.console = injector.get(ɵConsole);
|
5567 |
|
5568 | const ngZone = injector.get(NgZone);
|
5569 | this.isNgZoneEnabled = ngZone instanceof NgZone;
|
5570 | this.resetConfig(config);
|
5571 | this.currentUrlTree = createEmptyUrlTree();
|
5572 | this.rawUrlTree = this.currentUrlTree;
|
5573 | this.browserUrlTree = this.currentUrlTree;
|
5574 | this.configLoader = new RouterConfigLoader(loader, compiler, onLoadStart, onLoadEnd);
|
5575 | this.routerState = createEmptyState(this.currentUrlTree, this.rootComponentType);
|
5576 | this.transitions = new BehaviorSubject({
|
5577 | id: 0,
|
5578 | currentUrlTree: this.currentUrlTree,
|
5579 | currentRawUrl: this.currentUrlTree,
|
5580 | extractedUrl: this.urlHandlingStrategy.extract(this.currentUrlTree),
|
5581 | urlAfterRedirects: this.urlHandlingStrategy.extract(this.currentUrlTree),
|
5582 | rawUrl: this.currentUrlTree,
|
5583 | extras: {},
|
5584 | resolve: null,
|
5585 | reject: null,
|
5586 | promise: Promise.resolve(true),
|
5587 | source: 'imperative',
|
5588 | restoredState: null,
|
5589 | currentSnapshot: this.routerState.snapshot,
|
5590 | targetSnapshot: null,
|
5591 | currentRouterState: this.routerState,
|
5592 | targetRouterState: null,
|
5593 | guards: { canActivateChecks: [], canDeactivateChecks: [] },
|
5594 | guardsResult: null,
|
5595 | });
|
5596 | this.navigations = this.setupNavigations(this.transitions);
|
5597 | this.processNavigations();
|
5598 | }
|
5599 | |
5600 |
|
5601 |
|
5602 |
|
5603 |
|
5604 | setupNavigations(transitions) {
|
5605 |
|
5606 | const eventsSubject = (( (this.events)));
|
5607 | return ( (( (transitions.pipe(filter(( |
5608 |
|
5609 |
|
5610 |
|
5611 | t => t.id !== 0)),
|
5612 |
|
5613 | map(( |
5614 |
|
5615 |
|
5616 |
|
5617 | t => (( (Object.assign({}, t, { extractedUrl: this.urlHandlingStrategy.extract(t.rawUrl) })))))),
|
5618 |
|
5619 | switchMap(( |
5620 |
|
5621 |
|
5622 |
|
5623 | t => {
|
5624 |
|
5625 | let completed = false;
|
5626 |
|
5627 | let errored = false;
|
5628 | return of(t).pipe(
|
5629 |
|
5630 | tap(( |
5631 |
|
5632 |
|
5633 |
|
5634 | t => {
|
5635 | this.currentNavigation = {
|
5636 | id: t.id,
|
5637 | initialUrl: t.currentRawUrl,
|
5638 | extractedUrl: t.extractedUrl,
|
5639 | trigger: t.source,
|
5640 | extras: t.extras,
|
5641 | previousNavigation: this.lastSuccessfulNavigation ? Object.assign({}, this.lastSuccessfulNavigation, { previousNavigation: null }) :
|
5642 | null
|
5643 | };
|
5644 | })), switchMap(( |
5645 |
|
5646 |
|
5647 |
|
5648 | t => {
|
5649 |
|
5650 | const urlTransition = !this.navigated || t.extractedUrl.toString() !== this.browserUrlTree.toString();
|
5651 |
|
5652 | const processCurrentUrl = (this.onSameUrlNavigation === 'reload' ? true : urlTransition) &&
|
5653 | this.urlHandlingStrategy.shouldProcessUrl(t.rawUrl);
|
5654 | if (processCurrentUrl) {
|
5655 | return of(t).pipe(
|
5656 |
|
5657 | switchMap(( |
5658 |
|
5659 |
|
5660 |
|
5661 | t => {
|
5662 |
|
5663 | const transition = this.transitions.getValue();
|
5664 | eventsSubject.next(new NavigationStart(t.id, this.serializeUrl(t.extractedUrl), t.source, t.restoredState));
|
5665 | if (transition !== this.transitions.getValue()) {
|
5666 | return EMPTY;
|
5667 | }
|
5668 | return [t];
|
5669 | })),
|
5670 |
|
5671 |
|
5672 | switchMap(( |
5673 |
|
5674 |
|
5675 |
|
5676 | t => Promise.resolve(t))),
|
5677 |
|
5678 | applyRedirects$1(this.ngModule.injector, this.configLoader, this.urlSerializer, this.config),
|
5679 |
|
5680 | tap(( |
5681 |
|
5682 |
|
5683 |
|
5684 | t => {
|
5685 | this.currentNavigation = Object.assign({}, ( (this.currentNavigation)), { finalUrl: t.urlAfterRedirects });
|
5686 | })),
|
5687 |
|
5688 | recognize$1(this.rootComponentType, this.config, ( |
5689 |
|
5690 |
|
5691 |
|
5692 | (url) => this.serializeUrl(url)), this.paramsInheritanceStrategy, this.relativeLinkResolution),
|
5693 |
|
5694 | tap(( |
5695 |
|
5696 |
|
5697 |
|
5698 | t => {
|
5699 | if (this.urlUpdateStrategy === 'eager') {
|
5700 | if (!t.extras.skipLocationChange) {
|
5701 | this.setBrowserUrl(t.urlAfterRedirects, !!t.extras.replaceUrl, t.id, t.extras.state);
|
5702 | }
|
5703 | this.browserUrlTree = t.urlAfterRedirects;
|
5704 | }
|
5705 | })),
|
5706 |
|
5707 | tap(( |
5708 |
|
5709 |
|
5710 |
|
5711 | t => {
|
5712 |
|
5713 | const routesRecognized = new RoutesRecognized(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(t.urlAfterRedirects), ( (t.targetSnapshot)));
|
5714 | eventsSubject.next(routesRecognized);
|
5715 | })));
|
5716 | }
|
5717 | else {
|
5718 |
|
5719 | const processPreviousUrl = urlTransition && this.rawUrlTree &&
|
5720 | this.urlHandlingStrategy.shouldProcessUrl(this.rawUrlTree);
|
5721 | |
5722 |
|
5723 |
|
5724 | if (processPreviousUrl) {
|
5725 | const { id, extractedUrl, source, restoredState, extras } = t;
|
5726 |
|
5727 | const navStart = new NavigationStart(id, this.serializeUrl(extractedUrl), source, restoredState);
|
5728 | eventsSubject.next(navStart);
|
5729 |
|
5730 | const targetSnapshot = createEmptyState(extractedUrl, this.rootComponentType).snapshot;
|
5731 | return of(Object.assign({}, t, { targetSnapshot, urlAfterRedirects: extractedUrl, extras: Object.assign({}, extras, { skipLocationChange: false, replaceUrl: false }) }));
|
5732 | }
|
5733 | else {
|
5734 | |
5735 |
|
5736 |
|
5737 |
|
5738 | this.rawUrlTree = t.rawUrl;
|
5739 | this.browserUrlTree = t.urlAfterRedirects;
|
5740 | t.resolve(null);
|
5741 | return EMPTY;
|
5742 | }
|
5743 | }
|
5744 | })),
|
5745 |
|
5746 | switchTap(( |
5747 |
|
5748 |
|
5749 |
|
5750 | t => {
|
5751 | const { targetSnapshot, id: navigationId, extractedUrl: appliedUrlTree, rawUrl: rawUrlTree, extras: { skipLocationChange, replaceUrl } } = t;
|
5752 | return this.hooks.beforePreactivation(( (targetSnapshot)), {
|
5753 | navigationId,
|
5754 | appliedUrlTree,
|
5755 | rawUrlTree,
|
5756 | skipLocationChange: !!skipLocationChange,
|
5757 | replaceUrl: !!replaceUrl,
|
5758 | });
|
5759 | })),
|
5760 |
|
5761 | tap(( |
5762 |
|
5763 |
|
5764 |
|
5765 | t => {
|
5766 |
|
5767 | const guardsStart = new GuardsCheckStart(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(t.urlAfterRedirects), ( (t.targetSnapshot)));
|
5768 | this.triggerEvent(guardsStart);
|
5769 | })), map(( |
5770 |
|
5771 |
|
5772 |
|
5773 | t => (Object.assign({}, t, { guards: getAllRouteGuards(( (t.targetSnapshot)), t.currentSnapshot, this.rootContexts) })))), checkGuards(this.ngModule.injector, ( |
5774 |
|
5775 |
|
5776 |
|
5777 | (evt) => this.triggerEvent(evt))), tap(( |
5778 |
|
5779 |
|
5780 |
|
5781 | t => {
|
5782 | if (isUrlTree(t.guardsResult)) {
|
5783 |
|
5784 | const error = navigationCancelingError(`Redirecting to "${this.serializeUrl(t.guardsResult)}"`);
|
5785 | error.url = t.guardsResult;
|
5786 | throw error;
|
5787 | }
|
5788 | })), tap(( |
5789 |
|
5790 |
|
5791 |
|
5792 | t => {
|
5793 |
|
5794 | const guardsEnd = new GuardsCheckEnd(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(t.urlAfterRedirects), ( (t.targetSnapshot)), !!t.guardsResult);
|
5795 | this.triggerEvent(guardsEnd);
|
5796 | })), filter(( |
5797 |
|
5798 |
|
5799 |
|
5800 | t => {
|
5801 | if (!t.guardsResult) {
|
5802 | this.resetUrlToCurrentUrlTree();
|
5803 |
|
5804 | const navCancel = new NavigationCancel(t.id, this.serializeUrl(t.extractedUrl), '');
|
5805 | eventsSubject.next(navCancel);
|
5806 | t.resolve(false);
|
5807 | return false;
|
5808 | }
|
5809 | return true;
|
5810 | })),
|
5811 |
|
5812 | switchTap(( |
5813 |
|
5814 |
|
5815 |
|
5816 | t => {
|
5817 | if (t.guards.canActivateChecks.length) {
|
5818 | return of(t).pipe(tap(( |
5819 |
|
5820 |
|
5821 |
|
5822 | t => {
|
5823 |
|
5824 | const resolveStart = new ResolveStart(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(t.urlAfterRedirects), ( (t.targetSnapshot)));
|
5825 | this.triggerEvent(resolveStart);
|
5826 | })), resolveData(this.paramsInheritanceStrategy, this.ngModule.injector),
|
5827 | tap(( |
5828 |
|
5829 |
|
5830 |
|
5831 | t => {
|
5832 |
|
5833 | const resolveEnd = new ResolveEnd(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(t.urlAfterRedirects), ( (t.targetSnapshot)));
|
5834 | this.triggerEvent(resolveEnd);
|
5835 | })));
|
5836 | }
|
5837 | return undefined;
|
5838 | })),
|
5839 |
|
5840 | switchTap(( |
5841 |
|
5842 |
|
5843 |
|
5844 | (t) => {
|
5845 | const { targetSnapshot, id: navigationId, extractedUrl: appliedUrlTree, rawUrl: rawUrlTree, extras: { skipLocationChange, replaceUrl } } = t;
|
5846 | return this.hooks.afterPreactivation(( (targetSnapshot)), {
|
5847 | navigationId,
|
5848 | appliedUrlTree,
|
5849 | rawUrlTree,
|
5850 | skipLocationChange: !!skipLocationChange,
|
5851 | replaceUrl: !!replaceUrl,
|
5852 | });
|
5853 | })), map(( |
5854 |
|
5855 |
|
5856 |
|
5857 | (t) => {
|
5858 |
|
5859 | const targetRouterState = createRouterState(this.routeReuseStrategy, ( (t.targetSnapshot)), t.currentRouterState);
|
5860 | return (Object.assign({}, t, { targetRouterState }));
|
5861 | })),
|
5862 | |
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 | tap(( |
5868 |
|
5869 |
|
5870 |
|
5871 | (t) => {
|
5872 | this.currentUrlTree = t.urlAfterRedirects;
|
5873 | this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, t.rawUrl);
|
5874 | (( (this))).routerState = ( (t.targetRouterState));
|
5875 | if (this.urlUpdateStrategy === 'deferred') {
|
5876 | if (!t.extras.skipLocationChange) {
|
5877 | this.setBrowserUrl(this.rawUrlTree, !!t.extras.replaceUrl, t.id, t.extras.state);
|
5878 | }
|
5879 | this.browserUrlTree = t.urlAfterRedirects;
|
5880 | }
|
5881 | })), activateRoutes(this.rootContexts, this.routeReuseStrategy, ( |
5882 |
|
5883 |
|
5884 |
|
5885 | (evt) => this.triggerEvent(evt))), tap({ |
5886 |
|
5887 |
|
5888 | next() { completed = true; }, |
5889 |
|
5890 |
|
5891 | complete() { completed = true; } }), finalize(( |
5892 |
|
5893 |
|
5894 | () => {
|
5895 | |
5896 |
|
5897 |
|
5898 |
|
5899 |
|
5900 | if (!completed && !errored) {
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 | this.resetUrlToCurrentUrlTree();
|
5908 |
|
5909 | const navCancel = new NavigationCancel(t.id, this.serializeUrl(t.extractedUrl), `Navigation ID ${t.id} is not equal to the current navigation id ${this.navigationId}`);
|
5910 | eventsSubject.next(navCancel);
|
5911 | t.resolve(false);
|
5912 | }
|
5913 |
|
5914 |
|
5915 |
|
5916 | this.currentNavigation = null;
|
5917 | })), catchError(( |
5918 |
|
5919 |
|
5920 |
|
5921 | (e) => {
|
5922 | errored = true;
|
5923 | |
5924 |
|
5925 | if (isNavigationCancelingError(e)) {
|
5926 |
|
5927 | const redirecting = isUrlTree(e.url);
|
5928 | if (!redirecting) {
|
5929 |
|
5930 |
|
5931 |
|
5932 |
|
5933 |
|
5934 | this.navigated = true;
|
5935 | this.resetStateAndUrl(t.currentRouterState, t.currentUrlTree, t.rawUrl);
|
5936 | }
|
5937 |
|
5938 | const navCancel = new NavigationCancel(t.id, this.serializeUrl(t.extractedUrl), e.message);
|
5939 | eventsSubject.next(navCancel);
|
5940 | t.resolve(false);
|
5941 | if (redirecting) {
|
5942 | this.navigateByUrl(e.url);
|
5943 | }
|
5944 | |
5945 |
|
5946 | }
|
5947 | else {
|
5948 | this.resetStateAndUrl(t.currentRouterState, t.currentUrlTree, t.rawUrl);
|
5949 |
|
5950 | const navError = new NavigationError(t.id, this.serializeUrl(t.extractedUrl), e);
|
5951 | eventsSubject.next(navError);
|
5952 | try {
|
5953 | t.resolve(this.errorHandler(e));
|
5954 | }
|
5955 | catch (ee) {
|
5956 | t.reject(ee);
|
5957 | }
|
5958 | }
|
5959 | return EMPTY;
|
5960 | })));
|
5961 |
|
5962 | })))))));
|
5963 | }
|
5964 | |
5965 |
|
5966 |
|
5967 |
|
5968 |
|
5969 |
|
5970 | resetRootComponentType(rootComponentType) {
|
5971 | this.rootComponentType = rootComponentType;
|
5972 |
|
5973 |
|
5974 | this.routerState.root.component = this.rootComponentType;
|
5975 | }
|
5976 | |
5977 |
|
5978 |
|
5979 |
|
5980 | getTransition() {
|
5981 |
|
5982 | const transition = this.transitions.value;
|
5983 |
|
5984 |
|
5985 |
|
5986 | transition.urlAfterRedirects = this.browserUrlTree;
|
5987 | return transition;
|
5988 | }
|
5989 | |
5990 |
|
5991 |
|
5992 |
|
5993 |
|
5994 | setTransition(t) {
|
5995 | this.transitions.next(Object.assign({}, this.getTransition(), t));
|
5996 | }
|
5997 | |
5998 |
|
5999 |
|
6000 |
|
6001 | initialNavigation() {
|
6002 | this.setUpLocationChangeListener();
|
6003 | if (this.navigationId === 0) {
|
6004 | this.navigateByUrl(this.location.path(true), { replaceUrl: true });
|
6005 | }
|
6006 | }
|
6007 | |
6008 |
|
6009 |
|
6010 |
|
6011 | setUpLocationChangeListener() {
|
6012 |
|
6013 |
|
6014 |
|
6015 | if (!this.locationSubscription) {
|
6016 | this.locationSubscription = ( (this.location.subscribe(( |
6017 |
|
6018 |
|
6019 |
|
6020 | (change) => {
|
6021 |
|
6022 | let rawUrlTree = this.parseUrl(change['url']);
|
6023 |
|
6024 | const source = change['type'] === 'popstate' ? 'popstate' : 'hashchange';
|
6025 |
|
6026 |
|
6027 |
|
6028 | const state = change.state && change.state.navigationId ? change.state : null;
|
6029 | setTimeout(( |
6030 |
|
6031 |
|
6032 | () => { this.scheduleNavigation(rawUrlTree, source, state, { replaceUrl: true }); }), 0);
|
6033 | }))));
|
6034 | }
|
6035 | }
|
6036 | |
6037 |
|
6038 |
|
6039 |
|
6040 | get url() { return this.serializeUrl(this.currentUrlTree); }
|
6041 | |
6042 |
|
6043 |
|
6044 |
|
6045 | getCurrentNavigation() { return this.currentNavigation; }
|
6046 | |
6047 |
|
6048 |
|
6049 |
|
6050 |
|
6051 | triggerEvent(event) { (( (this.events))).next(event); }
|
6052 | |
6053 |
|
6054 |
|
6055 |
|
6056 |
|
6057 |
|
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 |
|
6067 |
|
6068 |
|
6069 | resetConfig(config) {
|
6070 | validateConfig(config);
|
6071 | this.config = config.map(standardizeConfig);
|
6072 | this.navigated = false;
|
6073 | this.lastSuccessfulId = -1;
|
6074 | }
|
6075 | |
6076 |
|
6077 |
|
6078 |
|
6079 | ngOnDestroy() { this.dispose(); }
|
6080 | |
6081 |
|
6082 |
|
6083 |
|
6084 | dispose() {
|
6085 | if (this.locationSubscription) {
|
6086 | this.locationSubscription.unsubscribe();
|
6087 | this.locationSubscription = ( (null));
|
6088 | }
|
6089 | }
|
6090 | |
6091 |
|
6092 |
|
6093 |
|
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 |
|
6099 |
|
6100 |
|
6101 |
|
6102 |
|
6103 |
|
6104 |
|
6105 |
|
6106 |
|
6107 |
|
6108 |
|
6109 |
|
6110 |
|
6111 |
|
6112 |
|
6113 |
|
6114 |
|
6115 |
|
6116 |
|
6117 |
|
6118 |
|
6119 |
|
6120 |
|
6121 |
|
6122 |
|
6123 |
|
6124 |
|
6125 |
|
6126 |
|
6127 |
|
6128 |
|
6129 |
|
6130 |
|
6131 |
|
6132 |
|
6133 |
|
6134 | createUrlTree(commands, navigationExtras = {}) {
|
6135 | const { relativeTo, queryParams, fragment, preserveQueryParams, queryParamsHandling, preserveFragment } = navigationExtras;
|
6136 | if (isDevMode() && preserveQueryParams && ( (console)) && ( (console.warn))) {
|
6137 | console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
|
6138 | }
|
6139 |
|
6140 | const a = relativeTo || this.routerState.root;
|
6141 |
|
6142 | const f = preserveFragment ? this.currentUrlTree.fragment : fragment;
|
6143 |
|
6144 | let q = null;
|
6145 | if (queryParamsHandling) {
|
6146 | switch (queryParamsHandling) {
|
6147 | case 'merge':
|
6148 | q = Object.assign({}, this.currentUrlTree.queryParams, queryParams);
|
6149 | break;
|
6150 | case 'preserve':
|
6151 | q = this.currentUrlTree.queryParams;
|
6152 | break;
|
6153 | default:
|
6154 | q = queryParams || null;
|
6155 | }
|
6156 | }
|
6157 | else {
|
6158 | q = preserveQueryParams ? this.currentUrlTree.queryParams : queryParams || null;
|
6159 | }
|
6160 | if (q !== null) {
|
6161 | q = this.removeEmptyProps(q);
|
6162 | }
|
6163 | return createUrlTree(a, this.currentUrlTree, commands, ( (q)), ( (f)));
|
6164 | }
|
6165 | |
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 |
|
6174 |
|
6175 |
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 |
|
6185 |
|
6186 | navigateByUrl(url, extras = { skipLocationChange: false }) {
|
6187 | if (isDevMode() && this.isNgZoneEnabled && !NgZone.isInAngularZone()) {
|
6188 | this.console.warn(`Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?`);
|
6189 | }
|
6190 |
|
6191 | const urlTree = isUrlTree(url) ? url : this.parseUrl(url);
|
6192 |
|
6193 | const mergedTree = this.urlHandlingStrategy.merge(urlTree, this.rawUrlTree);
|
6194 | return this.scheduleNavigation(mergedTree, 'imperative', null, extras);
|
6195 | }
|
6196 | |
6197 |
|
6198 |
|
6199 |
|
6200 |
|
6201 |
|
6202 |
|
6203 |
|
6204 |
|
6205 |
|
6206 |
|
6207 |
|
6208 |
|
6209 |
|
6210 |
|
6211 |
|
6212 |
|
6213 |
|
6214 |
|
6215 |
|
6216 |
|
6217 |
|
6218 |
|
6219 |
|
6220 |
|
6221 |
|
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 | navigate(commands, extras = { skipLocationChange: false }) {
|
6227 | validateCommands(commands);
|
6228 | return this.navigateByUrl(this.createUrlTree(commands, extras), extras);
|
6229 | }
|
6230 | |
6231 |
|
6232 |
|
6233 |
|
6234 |
|
6235 | serializeUrl(url) { return this.urlSerializer.serialize(url); }
|
6236 | |
6237 |
|
6238 |
|
6239 |
|
6240 |
|
6241 | parseUrl(url) {
|
6242 |
|
6243 | let urlTree;
|
6244 | try {
|
6245 | urlTree = this.urlSerializer.parse(url);
|
6246 | }
|
6247 | catch (e) {
|
6248 | urlTree = this.malformedUriErrorHandler(e, this.urlSerializer, url);
|
6249 | }
|
6250 | return urlTree;
|
6251 | }
|
6252 | |
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 |
|
6258 | isActive(url, exact) {
|
6259 | if (isUrlTree(url)) {
|
6260 | return containsTree(this.currentUrlTree, url, exact);
|
6261 | }
|
6262 |
|
6263 | const urlTree = this.parseUrl(url);
|
6264 | return containsTree(this.currentUrlTree, urlTree, exact);
|
6265 | }
|
6266 | |
6267 |
|
6268 |
|
6269 |
|
6270 |
|
6271 | removeEmptyProps(params) {
|
6272 | return Object.keys(params).reduce(( |
6273 |
|
6274 |
|
6275 |
|
6276 |
|
6277 | (result, key) => {
|
6278 |
|
6279 | const value = params[key];
|
6280 | if (value !== null && value !== undefined) {
|
6281 | result[key] = value;
|
6282 | }
|
6283 | return result;
|
6284 | }), {});
|
6285 | }
|
6286 | |
6287 |
|
6288 |
|
6289 |
|
6290 | processNavigations() {
|
6291 | this.navigations.subscribe(( |
6292 |
|
6293 |
|
6294 |
|
6295 | t => {
|
6296 | this.navigated = true;
|
6297 | this.lastSuccessfulId = t.id;
|
6298 | (( (this.events)))
|
6299 | .next(new NavigationEnd(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(this.currentUrlTree)));
|
6300 | this.lastSuccessfulNavigation = this.currentNavigation;
|
6301 | this.currentNavigation = null;
|
6302 | t.resolve(true);
|
6303 | }), ( |
6304 |
|
6305 |
|
6306 |
|
6307 | e => { this.console.warn(`Unhandled Navigation Error: `); }));
|
6308 | }
|
6309 | |
6310 |
|
6311 |
|
6312 |
|
6313 |
|
6314 |
|
6315 |
|
6316 |
|
6317 | scheduleNavigation(rawUrl, source, restoredState, extras) {
|
6318 |
|
6319 | const lastNavigation = this.getTransition();
|
6320 |
|
6321 |
|
6322 |
|
6323 | if (lastNavigation && source !== 'imperative' && lastNavigation.source === 'imperative' &&
|
6324 | lastNavigation.rawUrl.toString() === rawUrl.toString()) {
|
6325 | return Promise.resolve(true);
|
6326 | }
|
6327 |
|
6328 |
|
6329 |
|
6330 | if (lastNavigation && source == 'hashchange' && lastNavigation.source === 'popstate' &&
|
6331 | lastNavigation.rawUrl.toString() === rawUrl.toString()) {
|
6332 | return Promise.resolve(true);
|
6333 | }
|
6334 |
|
6335 |
|
6336 |
|
6337 | if (lastNavigation && source == 'popstate' && lastNavigation.source === 'hashchange' &&
|
6338 | lastNavigation.rawUrl.toString() === rawUrl.toString()) {
|
6339 | return Promise.resolve(true);
|
6340 | }
|
6341 |
|
6342 | let resolve = null;
|
6343 |
|
6344 | let reject = null;
|
6345 |
|
6346 | const promise = new Promise(( |
6347 |
|
6348 |
|
6349 |
|
6350 |
|
6351 | (res, rej) => {
|
6352 | resolve = res;
|
6353 | reject = rej;
|
6354 | }));
|
6355 |
|
6356 | const id = ++this.navigationId;
|
6357 | this.setTransition({
|
6358 | id,
|
6359 | source,
|
6360 | restoredState,
|
6361 | currentUrlTree: this.currentUrlTree,
|
6362 | currentRawUrl: this.rawUrlTree, rawUrl, extras, resolve, reject, promise,
|
6363 | currentSnapshot: this.routerState.snapshot,
|
6364 | currentRouterState: this.routerState
|
6365 | });
|
6366 |
|
6367 |
|
6368 | return promise.catch(( |
6369 |
|
6370 |
|
6371 |
|
6372 | (e) => { return Promise.reject(e); }));
|
6373 | }
|
6374 | |
6375 |
|
6376 |
|
6377 |
|
6378 |
|
6379 |
|
6380 |
|
6381 |
|
6382 | setBrowserUrl(url, replaceUrl, id, state) {
|
6383 |
|
6384 | const path = this.urlSerializer.serialize(url);
|
6385 | state = state || {};
|
6386 | if (this.location.isCurrentPathEqualTo(path) || replaceUrl) {
|
6387 |
|
6388 | this.location.replaceState(path, '', Object.assign({}, state, { navigationId: id }));
|
6389 | }
|
6390 | else {
|
6391 | this.location.go(path, '', Object.assign({}, state, { navigationId: id }));
|
6392 | }
|
6393 | }
|
6394 | |
6395 |
|
6396 |
|
6397 |
|
6398 |
|
6399 |
|
6400 |
|
6401 | resetStateAndUrl(storedState, storedUrl, rawUrl) {
|
6402 | (( (this))).routerState = storedState;
|
6403 | this.currentUrlTree = storedUrl;
|
6404 | this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
|
6405 | this.resetUrlToCurrentUrlTree();
|
6406 | }
|
6407 | |
6408 |
|
6409 |
|
6410 |
|
6411 | resetUrlToCurrentUrlTree() {
|
6412 | this.location.replaceState(this.urlSerializer.serialize(this.rawUrlTree), '', { navigationId: this.lastSuccessfulId });
|
6413 | }
|
6414 | }
|
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 | function validateCommands(commands) {
|
6420 | for (let i = 0; i < commands.length; i++) {
|
6421 |
|
6422 | const cmd = commands[i];
|
6423 | if (cmd == null) {
|
6424 | throw new Error(`The requested path contains ${cmd} segment at index ${i}`);
|
6425 | }
|
6426 | }
|
6427 | }
|
6428 |
|
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 |
|
6434 |
|
6435 |
|
6436 |
|
6437 |
|
6438 |
|
6439 |
|
6440 |
|
6441 |
|
6442 |
|
6443 |
|
6444 |
|
6445 |
|
6446 |
|
6447 |
|
6448 |
|
6449 |
|
6450 |
|
6451 |
|
6452 |
|
6453 |
|
6454 |
|
6455 |
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 |
|
6463 |
|
6464 |
|
6465 |
|
6466 |
|
6467 |
|
6468 |
|
6469 |
|
6470 |
|
6471 |
|
6472 |
|
6473 |
|
6474 |
|
6475 |
|
6476 |
|
6477 |
|
6478 |
|
6479 |
|
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 |
|
6495 |
|
6496 |
|
6497 |
|
6498 |
|
6499 |
|
6500 |
|
6501 |
|
6502 |
|
6503 |
|
6504 |
|
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 |
|
6510 |
|
6511 |
|
6512 |
|
6513 |
|
6514 |
|
6515 |
|
6516 |
|
6517 |
|
6518 |
|
6519 |
|
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 |
|
6525 |
|
6526 |
|
6527 | class RouterLink {
|
6528 | |
6529 |
|
6530 |
|
6531 |
|
6532 |
|
6533 |
|
6534 |
|
6535 | constructor(router, route, tabIndex, renderer, el) {
|
6536 | this.router = router;
|
6537 | this.route = route;
|
6538 | this.commands = [];
|
6539 | if (tabIndex == null) {
|
6540 | renderer.setAttribute(el.nativeElement, 'tabindex', '0');
|
6541 | }
|
6542 | }
|
6543 | |
6544 |
|
6545 |
|
6546 |
|
6547 | set routerLink(commands) {
|
6548 | if (commands != null) {
|
6549 | this.commands = Array.isArray(commands) ? commands : [commands];
|
6550 | }
|
6551 | else {
|
6552 | this.commands = [];
|
6553 | }
|
6554 | }
|
6555 | |
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 | set preserveQueryParams(value) {
|
6561 | if (isDevMode() && ( (console)) && ( (console.warn))) {
|
6562 | console.warn('preserveQueryParams is deprecated!, use queryParamsHandling instead.');
|
6563 | }
|
6564 | this.preserve = value;
|
6565 | }
|
6566 | |
6567 |
|
6568 |
|
6569 | onClick() {
|
6570 |
|
6571 | const extras = {
|
6572 | skipLocationChange: attrBoolValue(this.skipLocationChange),
|
6573 | replaceUrl: attrBoolValue(this.replaceUrl),
|
6574 | };
|
6575 | this.router.navigateByUrl(this.urlTree, extras);
|
6576 | return true;
|
6577 | }
|
6578 | |
6579 |
|
6580 |
|
6581 | get urlTree() {
|
6582 | return this.router.createUrlTree(this.commands, {
|
6583 | relativeTo: this.route,
|
6584 | queryParams: this.queryParams,
|
6585 | fragment: this.fragment,
|
6586 | preserveQueryParams: attrBoolValue(this.preserve),
|
6587 | queryParamsHandling: this.queryParamsHandling,
|
6588 | preserveFragment: attrBoolValue(this.preserveFragment),
|
6589 | });
|
6590 | }
|
6591 | }
|
6592 | RouterLink.decorators = [
|
6593 | { type: Directive, args: [{ selector: ':not(a):not(area)[routerLink]' },] }
|
6594 | ];
|
6595 |
|
6596 | RouterLink.ctorParameters = () => [
|
6597 | { type: Router },
|
6598 | { type: ActivatedRoute },
|
6599 | { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] },
|
6600 | { type: Renderer2 },
|
6601 | { type: ElementRef }
|
6602 | ];
|
6603 | RouterLink.propDecorators = {
|
6604 | queryParams: [{ type: Input }],
|
6605 | fragment: [{ type: Input }],
|
6606 | queryParamsHandling: [{ type: Input }],
|
6607 | preserveFragment: [{ type: Input }],
|
6608 | skipLocationChange: [{ type: Input }],
|
6609 | replaceUrl: [{ type: Input }],
|
6610 | state: [{ type: Input }],
|
6611 | routerLink: [{ type: Input }],
|
6612 | preserveQueryParams: [{ type: Input }],
|
6613 | onClick: [{ type: HostListener, args: ['click',] }]
|
6614 | };
|
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 | class RouterLinkWithHref {
|
6627 | |
6628 |
|
6629 |
|
6630 |
|
6631 |
|
6632 | constructor(router, route, locationStrategy) {
|
6633 | this.router = router;
|
6634 | this.route = route;
|
6635 | this.locationStrategy = locationStrategy;
|
6636 | this.commands = [];
|
6637 | this.subscription = router.events.subscribe(( |
6638 |
|
6639 |
|
6640 |
|
6641 | (s) => {
|
6642 | if (s instanceof NavigationEnd) {
|
6643 | this.updateTargetUrlAndHref();
|
6644 | }
|
6645 | }));
|
6646 | }
|
6647 | |
6648 |
|
6649 |
|
6650 |
|
6651 | set routerLink(commands) {
|
6652 | if (commands != null) {
|
6653 | this.commands = Array.isArray(commands) ? commands : [commands];
|
6654 | }
|
6655 | else {
|
6656 | this.commands = [];
|
6657 | }
|
6658 | }
|
6659 | |
6660 |
|
6661 |
|
6662 |
|
6663 | set preserveQueryParams(value) {
|
6664 | if (isDevMode() && ( (console)) && ( (console.warn))) {
|
6665 | console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
|
6666 | }
|
6667 | this.preserve = value;
|
6668 | }
|
6669 | |
6670 |
|
6671 |
|
6672 |
|
6673 | ngOnChanges(changes) { this.updateTargetUrlAndHref(); }
|
6674 | |
6675 |
|
6676 |
|
6677 | ngOnDestroy() { this.subscription.unsubscribe(); }
|
6678 | |
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 | onClick(button, ctrlKey, metaKey, shiftKey) {
|
6686 | if (button !== 0 || ctrlKey || metaKey || shiftKey) {
|
6687 | return true;
|
6688 | }
|
6689 | if (typeof this.target === 'string' && this.target != '_self') {
|
6690 | return true;
|
6691 | }
|
6692 |
|
6693 | const extras = {
|
6694 | skipLocationChange: attrBoolValue(this.skipLocationChange),
|
6695 | replaceUrl: attrBoolValue(this.replaceUrl),
|
6696 | state: this.state
|
6697 | };
|
6698 | this.router.navigateByUrl(this.urlTree, extras);
|
6699 | return false;
|
6700 | }
|
6701 | |
6702 |
|
6703 |
|
6704 |
|
6705 | updateTargetUrlAndHref() {
|
6706 | this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
|
6707 | }
|
6708 | |
6709 |
|
6710 |
|
6711 | get urlTree() {
|
6712 | return this.router.createUrlTree(this.commands, {
|
6713 | relativeTo: this.route,
|
6714 | queryParams: this.queryParams,
|
6715 | fragment: this.fragment,
|
6716 | preserveQueryParams: attrBoolValue(this.preserve),
|
6717 | queryParamsHandling: this.queryParamsHandling,
|
6718 | preserveFragment: attrBoolValue(this.preserveFragment),
|
6719 | });
|
6720 | }
|
6721 | }
|
6722 | RouterLinkWithHref.decorators = [
|
6723 | { type: Directive, args: [{ selector: 'a[routerLink],area[routerLink]' },] }
|
6724 | ];
|
6725 |
|
6726 | RouterLinkWithHref.ctorParameters = () => [
|
6727 | { type: Router },
|
6728 | { type: ActivatedRoute },
|
6729 | { type: LocationStrategy }
|
6730 | ];
|
6731 | RouterLinkWithHref.propDecorators = {
|
6732 | target: [{ type: HostBinding, args: ['attr.target',] }, { type: Input }],
|
6733 | queryParams: [{ type: Input }],
|
6734 | fragment: [{ type: Input }],
|
6735 | queryParamsHandling: [{ type: Input }],
|
6736 | preserveFragment: [{ type: Input }],
|
6737 | skipLocationChange: [{ type: Input }],
|
6738 | replaceUrl: [{ type: Input }],
|
6739 | state: [{ type: Input }],
|
6740 | href: [{ type: HostBinding }],
|
6741 | routerLink: [{ type: Input }],
|
6742 | preserveQueryParams: [{ type: Input }],
|
6743 | onClick: [{ type: HostListener, args: ['click', ['$event.button', '$event.ctrlKey', '$event.metaKey', '$event.shiftKey'],] }]
|
6744 | };
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 | function attrBoolValue(s) {
|
6750 | return s === '' || !!s;
|
6751 | }
|
6752 |
|
6753 |
|
6754 |
|
6755 |
|
6756 |
|
6757 |
|
6758 |
|
6759 |
|
6760 |
|
6761 |
|
6762 |
|
6763 |
|
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 |
|
6772 |
|
6773 |
|
6774 |
|
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 |
|
6783 |
|
6784 |
|
6785 |
|
6786 |
|
6787 |
|
6788 |
|
6789 |
|
6790 |
|
6791 |
|
6792 |
|
6793 |
|
6794 |
|
6795 |
|
6796 |
|
6797 |
|
6798 |
|
6799 |
|
6800 |
|
6801 |
|
6802 |
|
6803 |
|
6804 |
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 |
|
6811 |
|
6812 |
|
6813 |
|
6814 | class RouterLinkActive {
|
6815 | |
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 | constructor(router, element, renderer, link, linkWithHref) {
|
6823 | this.router = router;
|
6824 | this.element = element;
|
6825 | this.renderer = renderer;
|
6826 | this.link = link;
|
6827 | this.linkWithHref = linkWithHref;
|
6828 | this.classes = [];
|
6829 | this.isActive = false;
|
6830 | this.routerLinkActiveOptions = { exact: false };
|
6831 | this.subscription = router.events.subscribe(( |
6832 |
|
6833 |
|
6834 |
|
6835 | (s) => {
|
6836 | if (s instanceof NavigationEnd) {
|
6837 | this.update();
|
6838 | }
|
6839 | }));
|
6840 | }
|
6841 | |
6842 |
|
6843 |
|
6844 | ngAfterContentInit() {
|
6845 | this.links.changes.subscribe(( |
6846 |
|
6847 |
|
6848 |
|
6849 | _ => this.update()));
|
6850 | this.linksWithHrefs.changes.subscribe(( |
6851 |
|
6852 |
|
6853 |
|
6854 | _ => this.update()));
|
6855 | this.update();
|
6856 | }
|
6857 | |
6858 |
|
6859 |
|
6860 |
|
6861 | set routerLinkActive(data) {
|
6862 |
|
6863 | const classes = Array.isArray(data) ? data : data.split(' ');
|
6864 | this.classes = classes.filter(( |
6865 |
|
6866 |
|
6867 |
|
6868 | c => !!c));
|
6869 | }
|
6870 | |
6871 |
|
6872 |
|
6873 |
|
6874 | ngOnChanges(changes) { this.update(); }
|
6875 | |
6876 |
|
6877 |
|
6878 | ngOnDestroy() { this.subscription.unsubscribe(); }
|
6879 | |
6880 |
|
6881 |
|
6882 |
|
6883 | update() {
|
6884 | if (!this.links || !this.linksWithHrefs || !this.router.navigated)
|
6885 | return;
|
6886 | Promise.resolve().then(( |
6887 |
|
6888 |
|
6889 | () => {
|
6890 |
|
6891 | const hasActiveLinks = this.hasActiveLinks();
|
6892 | if (this.isActive !== hasActiveLinks) {
|
6893 | (( (this))).isActive = hasActiveLinks;
|
6894 | this.classes.forEach(( |
6895 |
|
6896 |
|
6897 |
|
6898 | (c) => {
|
6899 | if (hasActiveLinks) {
|
6900 | this.renderer.addClass(this.element.nativeElement, c);
|
6901 | }
|
6902 | else {
|
6903 | this.renderer.removeClass(this.element.nativeElement, c);
|
6904 | }
|
6905 | }));
|
6906 | }
|
6907 | }));
|
6908 | }
|
6909 | |
6910 |
|
6911 |
|
6912 |
|
6913 |
|
6914 | isLinkActive(router) {
|
6915 | return ( |
6916 |
|
6917 |
|
6918 |
|
6919 | (link) => router.isActive(link.urlTree, this.routerLinkActiveOptions.exact));
|
6920 | }
|
6921 | |
6922 |
|
6923 |
|
6924 |
|
6925 | hasActiveLinks() {
|
6926 |
|
6927 | const isActiveCheckFn = this.isLinkActive(this.router);
|
6928 | return this.link && isActiveCheckFn(this.link) ||
|
6929 | this.linkWithHref && isActiveCheckFn(this.linkWithHref) ||
|
6930 | this.links.some(isActiveCheckFn) || this.linksWithHrefs.some(isActiveCheckFn);
|
6931 | }
|
6932 | }
|
6933 | RouterLinkActive.decorators = [
|
6934 | { type: Directive, args: [{
|
6935 | selector: '[routerLinkActive]',
|
6936 | exportAs: 'routerLinkActive',
|
6937 | },] }
|
6938 | ];
|
6939 |
|
6940 | RouterLinkActive.ctorParameters = () => [
|
6941 | { type: Router },
|
6942 | { type: ElementRef },
|
6943 | { type: Renderer2 },
|
6944 | { type: RouterLink, decorators: [{ type: Optional }] },
|
6945 | { type: RouterLinkWithHref, decorators: [{ type: Optional }] }
|
6946 | ];
|
6947 | RouterLinkActive.propDecorators = {
|
6948 | links: [{ type: ContentChildren, args: [RouterLink, { descendants: true },] }],
|
6949 | linksWithHrefs: [{ type: ContentChildren, args: [RouterLinkWithHref, { descendants: true },] }],
|
6950 | routerLinkActiveOptions: [{ type: Input }],
|
6951 | routerLinkActive: [{ type: Input }]
|
6952 | };
|
6953 |
|
6954 |
|
6955 |
|
6956 |
|
6957 |
|
6958 |
|
6959 |
|
6960 |
|
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 |
|
6970 | class OutletContext {
|
6971 | constructor() {
|
6972 | this.outlet = null;
|
6973 | this.route = null;
|
6974 | this.resolver = null;
|
6975 | this.children = new ChildrenOutletContexts();
|
6976 | this.attachRef = null;
|
6977 | }
|
6978 | }
|
6979 |
|
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 | class ChildrenOutletContexts {
|
6985 | constructor() {
|
6986 |
|
6987 | this.contexts = new Map();
|
6988 | }
|
6989 | |
6990 |
|
6991 |
|
6992 |
|
6993 |
|
6994 |
|
6995 | onChildOutletCreated(childName, outlet) {
|
6996 |
|
6997 | const context = this.getOrCreateContext(childName);
|
6998 | context.outlet = outlet;
|
6999 | this.contexts.set(childName, context);
|
7000 | }
|
7001 | |
7002 |
|
7003 |
|
7004 |
|
7005 |
|
7006 |
|
7007 |
|
7008 | onChildOutletDestroyed(childName) {
|
7009 |
|
7010 | const context = this.getContext(childName);
|
7011 | if (context) {
|
7012 | context.outlet = null;
|
7013 | }
|
7014 | }
|
7015 | |
7016 |
|
7017 |
|
7018 |
|
7019 |
|
7020 | onOutletDeactivated() {
|
7021 |
|
7022 | const contexts = this.contexts;
|
7023 | this.contexts = new Map();
|
7024 | return contexts;
|
7025 | }
|
7026 | |
7027 |
|
7028 |
|
7029 |
|
7030 | onOutletReAttached(contexts) { this.contexts = contexts; }
|
7031 | |
7032 |
|
7033 |
|
7034 |
|
7035 | getOrCreateContext(childName) {
|
7036 |
|
7037 | let context = this.getContext(childName);
|
7038 | if (!context) {
|
7039 | context = new OutletContext();
|
7040 | this.contexts.set(childName, context);
|
7041 | }
|
7042 | return context;
|
7043 | }
|
7044 | |
7045 |
|
7046 |
|
7047 |
|
7048 | getContext(childName) { return this.contexts.get(childName) || null; }
|
7049 | }
|
7050 |
|
7051 |
|
7052 |
|
7053 |
|
7054 |
|
7055 |
|
7056 |
|
7057 |
|
7058 |
|
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 |
|
7064 |
|
7065 |
|
7066 |
|
7067 |
|
7068 |
|
7069 |
|
7070 |
|
7071 |
|
7072 |
|
7073 |
|
7074 |
|
7075 |
|
7076 |
|
7077 |
|
7078 | class RouterOutlet {
|
7079 | |
7080 |
|
7081 |
|
7082 |
|
7083 |
|
7084 |
|
7085 |
|
7086 | constructor(parentContexts, location, resolver, name, changeDetector) {
|
7087 | this.parentContexts = parentContexts;
|
7088 | this.location = location;
|
7089 | this.resolver = resolver;
|
7090 | this.changeDetector = changeDetector;
|
7091 | this.activated = null;
|
7092 | this._activatedRoute = null;
|
7093 | this.activateEvents = new EventEmitter();
|
7094 | this.deactivateEvents = new EventEmitter();
|
7095 | this.name = name || PRIMARY_OUTLET;
|
7096 | parentContexts.onChildOutletCreated(this.name, this);
|
7097 | }
|
7098 | |
7099 |
|
7100 |
|
7101 | ngOnDestroy() { this.parentContexts.onChildOutletDestroyed(this.name); }
|
7102 | |
7103 |
|
7104 |
|
7105 | ngOnInit() {
|
7106 | if (!this.activated) {
|
7107 |
|
7108 |
|
7109 |
|
7110 | const context = this.parentContexts.getContext(this.name);
|
7111 | if (context && context.route) {
|
7112 | if (context.attachRef) {
|
7113 |
|
7114 | this.attach(context.attachRef, context.route);
|
7115 | }
|
7116 | else {
|
7117 |
|
7118 | this.activateWith(context.route, context.resolver || null);
|
7119 | }
|
7120 | }
|
7121 | }
|
7122 | }
|
7123 | |
7124 |
|
7125 |
|
7126 | get isActivated() { return !!this.activated; }
|
7127 | |
7128 |
|
7129 |
|
7130 | get component() {
|
7131 | if (!this.activated)
|
7132 | throw new Error('Outlet is not activated');
|
7133 | return this.activated.instance;
|
7134 | }
|
7135 | |
7136 |
|
7137 |
|
7138 | get activatedRoute() {
|
7139 | if (!this.activated)
|
7140 | throw new Error('Outlet is not activated');
|
7141 | return ( (this._activatedRoute));
|
7142 | }
|
7143 | |
7144 |
|
7145 |
|
7146 | get activatedRouteData() {
|
7147 | if (this._activatedRoute) {
|
7148 | return this._activatedRoute.snapshot.data;
|
7149 | }
|
7150 | return {};
|
7151 | }
|
7152 | |
7153 |
|
7154 |
|
7155 |
|
7156 | detach() {
|
7157 | if (!this.activated)
|
7158 | throw new Error('Outlet is not activated');
|
7159 | this.location.detach();
|
7160 |
|
7161 | const cmp = this.activated;
|
7162 | this.activated = null;
|
7163 | this._activatedRoute = null;
|
7164 | return cmp;
|
7165 | }
|
7166 | |
7167 |
|
7168 |
|
7169 |
|
7170 |
|
7171 |
|
7172 | attach(ref, activatedRoute) {
|
7173 | this.activated = ref;
|
7174 | this._activatedRoute = activatedRoute;
|
7175 | this.location.insert(ref.hostView);
|
7176 | }
|
7177 | |
7178 |
|
7179 |
|
7180 | deactivate() {
|
7181 | if (this.activated) {
|
7182 |
|
7183 | const c = this.component;
|
7184 | this.activated.destroy();
|
7185 | this.activated = null;
|
7186 | this._activatedRoute = null;
|
7187 | this.deactivateEvents.emit(c);
|
7188 | }
|
7189 | }
|
7190 | |
7191 |
|
7192 |
|
7193 |
|
7194 |
|
7195 | activateWith(activatedRoute, resolver) {
|
7196 | if (this.isActivated) {
|
7197 | throw new Error('Cannot activate an already activated outlet');
|
7198 | }
|
7199 | this._activatedRoute = activatedRoute;
|
7200 |
|
7201 | const snapshot = activatedRoute._futureSnapshot;
|
7202 |
|
7203 | const component = ( (( (snapshot.routeConfig)).component));
|
7204 | resolver = resolver || this.resolver;
|
7205 |
|
7206 | const factory = resolver.resolveComponentFactory(component);
|
7207 |
|
7208 | const childContexts = this.parentContexts.getOrCreateContext(this.name).children;
|
7209 |
|
7210 | const injector = new OutletInjector(activatedRoute, childContexts, this.location.injector);
|
7211 | this.activated = this.location.createComponent(factory, this.location.length, injector);
|
7212 |
|
7213 |
|
7214 | this.changeDetector.markForCheck();
|
7215 | this.activateEvents.emit(this.activated.instance);
|
7216 | }
|
7217 | }
|
7218 | RouterOutlet.decorators = [
|
7219 | { type: Directive, args: [{ selector: 'router-outlet', exportAs: 'outlet' },] }
|
7220 | ];
|
7221 |
|
7222 | RouterOutlet.ctorParameters = () => [
|
7223 | { type: ChildrenOutletContexts },
|
7224 | { type: ViewContainerRef },
|
7225 | { type: ComponentFactoryResolver },
|
7226 | { type: String, decorators: [{ type: Attribute, args: ['name',] }] },
|
7227 | { type: ChangeDetectorRef }
|
7228 | ];
|
7229 | RouterOutlet.propDecorators = {
|
7230 | activateEvents: [{ type: Output, args: ['activate',] }],
|
7231 | deactivateEvents: [{ type: Output, args: ['deactivate',] }]
|
7232 | };
|
7233 | class OutletInjector {
|
7234 | |
7235 |
|
7236 |
|
7237 |
|
7238 |
|
7239 | constructor(route, childContexts, parent) {
|
7240 | this.route = route;
|
7241 | this.childContexts = childContexts;
|
7242 | this.parent = parent;
|
7243 | }
|
7244 | |
7245 |
|
7246 |
|
7247 |
|
7248 |
|
7249 | get(token, notFoundValue) {
|
7250 | if (token === ActivatedRoute) {
|
7251 | return this.route;
|
7252 | }
|
7253 | if (token === ChildrenOutletContexts) {
|
7254 | return this.childContexts;
|
7255 | }
|
7256 | return this.parent.get(token, notFoundValue);
|
7257 | }
|
7258 | }
|
7259 |
|
7260 |
|
7261 |
|
7262 |
|
7263 |
|
7264 |
|
7265 |
|
7266 |
|
7267 |
|
7268 |
|
7269 |
|
7270 |
|
7271 |
|
7272 | class PreloadingStrategy {
|
7273 | }
|
7274 |
|
7275 |
|
7276 |
|
7277 |
|
7278 |
|
7279 |
|
7280 |
|
7281 |
|
7282 |
|
7283 |
|
7284 |
|
7285 | class PreloadAllModules {
|
7286 | |
7287 |
|
7288 |
|
7289 |
|
7290 |
|
7291 | preload(route, fn) {
|
7292 | return fn().pipe(catchError(( |
7293 |
|
7294 |
|
7295 | () => of(null))));
|
7296 | }
|
7297 | }
|
7298 |
|
7299 |
|
7300 |
|
7301 |
|
7302 |
|
7303 |
|
7304 |
|
7305 |
|
7306 |
|
7307 | class NoPreloading {
|
7308 | |
7309 |
|
7310 |
|
7311 |
|
7312 |
|
7313 | preload(route, fn) { return of(null); }
|
7314 | }
|
7315 |
|
7316 |
|
7317 |
|
7318 |
|
7319 |
|
7320 |
|
7321 |
|
7322 |
|
7323 |
|
7324 |
|
7325 |
|
7326 |
|
7327 | class RouterPreloader {
|
7328 | |
7329 |
|
7330 |
|
7331 |
|
7332 |
|
7333 |
|
7334 |
|
7335 | constructor(router, moduleLoader, compiler, injector, preloadingStrategy) {
|
7336 | this.router = router;
|
7337 | this.injector = injector;
|
7338 | this.preloadingStrategy = preloadingStrategy;
|
7339 |
|
7340 | const onStartLoad = ( |
7341 |
|
7342 |
|
7343 |
|
7344 | (r) => router.triggerEvent(new RouteConfigLoadStart(r)));
|
7345 |
|
7346 | const onEndLoad = ( |
7347 |
|
7348 |
|
7349 |
|
7350 | (r) => router.triggerEvent(new RouteConfigLoadEnd(r)));
|
7351 | this.loader = new RouterConfigLoader(moduleLoader, compiler, onStartLoad, onEndLoad);
|
7352 | }
|
7353 | |
7354 |
|
7355 |
|
7356 | setUpPreloading() {
|
7357 | this.subscription =
|
7358 | this.router.events
|
7359 | .pipe(filter(( |
7360 |
|
7361 |
|
7362 |
|
7363 | (e) => e instanceof NavigationEnd)), concatMap(( |
7364 |
|
7365 |
|
7366 | () => this.preload())))
|
7367 | .subscribe(( |
7368 |
|
7369 |
|
7370 | () => { }));
|
7371 | }
|
7372 | |
7373 |
|
7374 |
|
7375 | preload() {
|
7376 |
|
7377 | const ngModule = this.injector.get(NgModuleRef);
|
7378 | return this.processRoutes(ngModule, this.router.config);
|
7379 | }
|
7380 |
|
7381 |
|
7382 |
|
7383 | |
7384 |
|
7385 |
|
7386 | ngOnDestroy() { this.subscription.unsubscribe(); }
|
7387 | |
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 | processRoutes(ngModule, routes) {
|
7394 |
|
7395 | const res = [];
|
7396 | for (const route of routes) {
|
7397 |
|
7398 | if (route.loadChildren && !route.canLoad && route._loadedConfig) {
|
7399 |
|
7400 | const childConfig = route._loadedConfig;
|
7401 | res.push(this.processRoutes(childConfig.module, childConfig.routes));
|
7402 |
|
7403 | }
|
7404 | else if (route.loadChildren && !route.canLoad) {
|
7405 | res.push(this.preloadConfig(ngModule, route));
|
7406 |
|
7407 | }
|
7408 | else if (route.children) {
|
7409 | res.push(this.processRoutes(ngModule, route.children));
|
7410 | }
|
7411 | }
|
7412 | return from(res).pipe(mergeAll(), map(( |
7413 |
|
7414 |
|
7415 |
|
7416 | (_) => void 0)));
|
7417 | }
|
7418 | |
7419 |
|
7420 |
|
7421 |
|
7422 |
|
7423 |
|
7424 | preloadConfig(ngModule, route) {
|
7425 | return this.preloadingStrategy.preload(route, ( |
7426 |
|
7427 |
|
7428 | () => {
|
7429 |
|
7430 | const loaded$ = this.loader.load(ngModule.injector, route);
|
7431 | return loaded$.pipe(mergeMap(( |
7432 |
|
7433 |
|
7434 |
|
7435 | (config) => {
|
7436 | route._loadedConfig = config;
|
7437 | return this.processRoutes(config.module, config.routes);
|
7438 | })));
|
7439 | }));
|
7440 | }
|
7441 | }
|
7442 | RouterPreloader.decorators = [
|
7443 | { type: Injectable }
|
7444 | ];
|
7445 |
|
7446 | RouterPreloader.ctorParameters = () => [
|
7447 | { type: Router },
|
7448 | { type: NgModuleFactoryLoader },
|
7449 | { type: Compiler },
|
7450 | { type: Injector },
|
7451 | { type: PreloadingStrategy }
|
7452 | ];
|
7453 |
|
7454 |
|
7455 |
|
7456 |
|
7457 |
|
7458 | class RouterScroller {
|
7459 | |
7460 |
|
7461 |
|
7462 |
|
7463 |
|
7464 | constructor(router, viewportScroller, options = {}) {
|
7465 | this.router = router;
|
7466 | this.viewportScroller = viewportScroller;
|
7467 | this.options = options;
|
7468 | this.lastId = 0;
|
7469 | this.lastSource = 'imperative';
|
7470 | this.restoredId = 0;
|
7471 | this.store = {};
|
7472 |
|
7473 | options.scrollPositionRestoration = options.scrollPositionRestoration || 'disabled';
|
7474 | options.anchorScrolling = options.anchorScrolling || 'disabled';
|
7475 | }
|
7476 | |
7477 |
|
7478 |
|
7479 | init() {
|
7480 |
|
7481 |
|
7482 |
|
7483 | if (this.options.scrollPositionRestoration !== 'disabled') {
|
7484 | this.viewportScroller.setHistoryScrollRestoration('manual');
|
7485 | }
|
7486 | this.routerEventsSubscription = this.createScrollEvents();
|
7487 | this.scrollEventsSubscription = this.consumeScrollEvents();
|
7488 | }
|
7489 | |
7490 |
|
7491 |
|
7492 |
|
7493 | createScrollEvents() {
|
7494 | return this.router.events.subscribe(( |
7495 |
|
7496 |
|
7497 |
|
7498 | e => {
|
7499 | if (e instanceof NavigationStart) {
|
7500 |
|
7501 | this.store[this.lastId] = this.viewportScroller.getScrollPosition();
|
7502 | this.lastSource = e.navigationTrigger;
|
7503 | this.restoredId = e.restoredState ? e.restoredState.navigationId : 0;
|
7504 | }
|
7505 | else if (e instanceof NavigationEnd) {
|
7506 | this.lastId = e.id;
|
7507 | this.scheduleScrollEvent(e, this.router.parseUrl(e.urlAfterRedirects).fragment);
|
7508 | }
|
7509 | }));
|
7510 | }
|
7511 | |
7512 |
|
7513 |
|
7514 |
|
7515 | consumeScrollEvents() {
|
7516 | return this.router.events.subscribe(( |
7517 |
|
7518 |
|
7519 |
|
7520 | e => {
|
7521 | if (!(e instanceof Scroll))
|
7522 | return;
|
7523 |
|
7524 | if (e.position) {
|
7525 | if (this.options.scrollPositionRestoration === 'top') {
|
7526 | this.viewportScroller.scrollToPosition([0, 0]);
|
7527 | }
|
7528 | else if (this.options.scrollPositionRestoration === 'enabled') {
|
7529 | this.viewportScroller.scrollToPosition(e.position);
|
7530 | }
|
7531 |
|
7532 | }
|
7533 | else {
|
7534 | if (e.anchor && this.options.anchorScrolling === 'enabled') {
|
7535 | this.viewportScroller.scrollToAnchor(e.anchor);
|
7536 | }
|
7537 | else if (this.options.scrollPositionRestoration !== 'disabled') {
|
7538 | this.viewportScroller.scrollToPosition([0, 0]);
|
7539 | }
|
7540 | }
|
7541 | }));
|
7542 | }
|
7543 | |
7544 |
|
7545 |
|
7546 |
|
7547 |
|
7548 |
|
7549 | scheduleScrollEvent(routerEvent, anchor) {
|
7550 | this.router.triggerEvent(new Scroll(routerEvent, this.lastSource === 'popstate' ? this.store[this.restoredId] : null, anchor));
|
7551 | }
|
7552 | |
7553 |
|
7554 |
|
7555 | ngOnDestroy() {
|
7556 | if (this.routerEventsSubscription) {
|
7557 | this.routerEventsSubscription.unsubscribe();
|
7558 | }
|
7559 | if (this.scrollEventsSubscription) {
|
7560 | this.scrollEventsSubscription.unsubscribe();
|
7561 | }
|
7562 | }
|
7563 | }
|
7564 |
|
7565 |
|
7566 |
|
7567 |
|
7568 |
|
7569 |
|
7570 |
|
7571 |
|
7572 |
|
7573 | const ROUTER_DIRECTIVES = [RouterOutlet, RouterLink, RouterLinkWithHref, RouterLinkActive, ɵEmptyOutletComponent];
|
7574 |
|
7575 |
|
7576 |
|
7577 |
|
7578 |
|
7579 |
|
7580 | const ROUTER_CONFIGURATION = new InjectionToken('ROUTER_CONFIGURATION');
|
7581 |
|
7582 |
|
7583 |
|
7584 |
|
7585 | const ROUTER_FORROOT_GUARD = new InjectionToken('ROUTER_FORROOT_GUARD');
|
7586 | const ɵ0 = { enableTracing: false };
|
7587 |
|
7588 | const ROUTER_PROVIDERS = [
|
7589 | Location,
|
7590 | { provide: UrlSerializer, useClass: DefaultUrlSerializer },
|
7591 | {
|
7592 | provide: Router,
|
7593 | useFactory: setupRouter,
|
7594 | deps: [
|
7595 | ApplicationRef, UrlSerializer, ChildrenOutletContexts, Location, Injector,
|
7596 | NgModuleFactoryLoader, Compiler, ROUTES, ROUTER_CONFIGURATION,
|
7597 | [UrlHandlingStrategy, new Optional()], [RouteReuseStrategy, new Optional()]
|
7598 | ]
|
7599 | },
|
7600 | ChildrenOutletContexts,
|
7601 | { provide: ActivatedRoute, useFactory: rootRoute, deps: [Router] },
|
7602 | { provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader },
|
7603 | RouterPreloader,
|
7604 | NoPreloading,
|
7605 | PreloadAllModules,
|
7606 | { provide: ROUTER_CONFIGURATION, useValue: ɵ0 },
|
7607 | ];
|
7608 |
|
7609 |
|
7610 |
|
7611 | function routerNgProbeToken() {
|
7612 | return new NgProbeToken('Router', Router);
|
7613 | }
|
7614 |
|
7615 |
|
7616 |
|
7617 |
|
7618 |
|
7619 |
|
7620 |
|
7621 |
|
7622 |
|
7623 |
|
7624 |
|
7625 |
|
7626 |
|
7627 |
|
7628 |
|
7629 |
|
7630 |
|
7631 |
|
7632 |
|
7633 |
|
7634 |
|
7635 |
|
7636 |
|
7637 |
|
7638 |
|
7639 |
|
7640 |
|
7641 |
|
7642 |
|
7643 |
|
7644 |
|
7645 |
|
7646 |
|
7647 |
|
7648 |
|
7649 |
|
7650 |
|
7651 |
|
7652 |
|
7653 |
|
7654 |
|
7655 |
|
7656 |
|
7657 |
|
7658 |
|
7659 |
|
7660 |
|
7661 |
|
7662 |
|
7663 |
|
7664 |
|
7665 | class RouterModule {
|
7666 |
|
7667 | |
7668 |
|
7669 |
|
7670 |
|
7671 | constructor(guard, router) { }
|
7672 | |
7673 |
|
7674 |
|
7675 |
|
7676 |
|
7677 |
|
7678 |
|
7679 |
|
7680 | static forRoot(routes, config) {
|
7681 | return {
|
7682 | ngModule: RouterModule,
|
7683 | providers: [
|
7684 | ROUTER_PROVIDERS,
|
7685 | provideRoutes(routes),
|
7686 | {
|
7687 | provide: ROUTER_FORROOT_GUARD,
|
7688 | useFactory: provideForRootGuard,
|
7689 | deps: [[Router, new Optional(), new SkipSelf()]]
|
7690 | },
|
7691 | { provide: ROUTER_CONFIGURATION, useValue: config ? config : {} },
|
7692 | {
|
7693 | provide: LocationStrategy,
|
7694 | useFactory: provideLocationStrategy,
|
7695 | deps: [
|
7696 | PlatformLocation, [new Inject(APP_BASE_HREF), new Optional()], ROUTER_CONFIGURATION
|
7697 | ]
|
7698 | },
|
7699 | {
|
7700 | provide: RouterScroller,
|
7701 | useFactory: createRouterScroller,
|
7702 | deps: [Router, ViewportScroller, ROUTER_CONFIGURATION]
|
7703 | },
|
7704 | {
|
7705 | provide: PreloadingStrategy,
|
7706 | useExisting: config && config.preloadingStrategy ? config.preloadingStrategy :
|
7707 | NoPreloading
|
7708 | },
|
7709 | { provide: NgProbeToken, multi: true, useFactory: routerNgProbeToken },
|
7710 | provideRouterInitializer(),
|
7711 | ],
|
7712 | };
|
7713 | }
|
7714 | |
7715 |
|
7716 |
|
7717 |
|
7718 |
|
7719 | static forChild(routes) {
|
7720 | return { ngModule: RouterModule, providers: [provideRoutes(routes)] };
|
7721 | }
|
7722 | }
|
7723 | RouterModule.decorators = [
|
7724 | { type: NgModule, args: [{
|
7725 | declarations: ROUTER_DIRECTIVES,
|
7726 | exports: ROUTER_DIRECTIVES,
|
7727 | entryComponents: [ɵEmptyOutletComponent]
|
7728 | },] }
|
7729 | ];
|
7730 |
|
7731 | RouterModule.ctorParameters = () => [
|
7732 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [ROUTER_FORROOT_GUARD,] }] },
|
7733 | { type: Router, decorators: [{ type: Optional }] }
|
7734 | ];
|
7735 |
|
7736 |
|
7737 |
|
7738 |
|
7739 |
|
7740 |
|
7741 | function createRouterScroller(router, viewportScroller, config) {
|
7742 | if (config.scrollOffset) {
|
7743 | viewportScroller.setOffset(config.scrollOffset);
|
7744 | }
|
7745 | return new RouterScroller(router, viewportScroller, config);
|
7746 | }
|
7747 |
|
7748 |
|
7749 |
|
7750 |
|
7751 |
|
7752 |
|
7753 | function provideLocationStrategy(platformLocationStrategy, baseHref, options = {}) {
|
7754 | return options.useHash ? new HashLocationStrategy(platformLocationStrategy, baseHref) :
|
7755 | new PathLocationStrategy(platformLocationStrategy, baseHref);
|
7756 | }
|
7757 |
|
7758 |
|
7759 |
|
7760 |
|
7761 | function provideForRootGuard(router) {
|
7762 | if (router) {
|
7763 | throw new Error(`RouterModule.forRoot() called twice. Lazy loaded modules should use RouterModule.forChild() instead.`);
|
7764 | }
|
7765 | return 'guarded';
|
7766 | }
|
7767 |
|
7768 |
|
7769 |
|
7770 |
|
7771 |
|
7772 |
|
7773 |
|
7774 |
|
7775 |
|
7776 |
|
7777 |
|
7778 |
|
7779 |
|
7780 |
|
7781 |
|
7782 |
|
7783 |
|
7784 | function provideRoutes(routes) {
|
7785 | return [
|
7786 | { provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes },
|
7787 | { provide: ROUTES, multi: true, useValue: routes },
|
7788 | ];
|
7789 | }
|
7790 |
|
7791 |
|
7792 |
|
7793 |
|
7794 |
|
7795 |
|
7796 |
|
7797 |
|
7798 |
|
7799 |
|
7800 |
|
7801 |
|
7802 |
|
7803 |
|
7804 | function setupRouter(ref, urlSerializer, contexts, location, injector, loader, compiler, config, opts = {}, urlHandlingStrategy, routeReuseStrategy) {
|
7805 |
|
7806 | const router = new Router(null, urlSerializer, contexts, location, injector, loader, compiler, flatten(config));
|
7807 | if (urlHandlingStrategy) {
|
7808 | router.urlHandlingStrategy = urlHandlingStrategy;
|
7809 | }
|
7810 | if (routeReuseStrategy) {
|
7811 | router.routeReuseStrategy = routeReuseStrategy;
|
7812 | }
|
7813 | if (opts.errorHandler) {
|
7814 | router.errorHandler = opts.errorHandler;
|
7815 | }
|
7816 | if (opts.malformedUriErrorHandler) {
|
7817 | router.malformedUriErrorHandler = opts.malformedUriErrorHandler;
|
7818 | }
|
7819 | if (opts.enableTracing) {
|
7820 |
|
7821 | const dom = ɵgetDOM();
|
7822 | router.events.subscribe(( |
7823 |
|
7824 |
|
7825 |
|
7826 | (e) => {
|
7827 | dom.logGroup(`Router Event: ${((/** @type {?} */ (e.constructor))).name}`);
|
7828 | dom.log(e.toString());
|
7829 | dom.log(e);
|
7830 | dom.logGroupEnd();
|
7831 | }));
|
7832 | }
|
7833 | if (opts.onSameUrlNavigation) {
|
7834 | router.onSameUrlNavigation = opts.onSameUrlNavigation;
|
7835 | }
|
7836 | if (opts.paramsInheritanceStrategy) {
|
7837 | router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
|
7838 | }
|
7839 | if (opts.urlUpdateStrategy) {
|
7840 | router.urlUpdateStrategy = opts.urlUpdateStrategy;
|
7841 | }
|
7842 | if (opts.relativeLinkResolution) {
|
7843 | router.relativeLinkResolution = opts.relativeLinkResolution;
|
7844 | }
|
7845 | return router;
|
7846 | }
|
7847 |
|
7848 |
|
7849 |
|
7850 |
|
7851 | function rootRoute(router) {
|
7852 | return router.routerState.root;
|
7853 | }
|
7854 |
|
7855 |
|
7856 |
|
7857 |
|
7858 |
|
7859 |
|
7860 |
|
7861 |
|
7862 |
|
7863 |
|
7864 |
|
7865 | class RouterInitializer {
|
7866 | |
7867 |
|
7868 |
|
7869 | constructor(injector) {
|
7870 | this.injector = injector;
|
7871 | this.initNavigation = false;
|
7872 | this.resultOfPreactivationDone = new Subject();
|
7873 | }
|
7874 | |
7875 |
|
7876 |
|
7877 | appInitializer() {
|
7878 |
|
7879 | const p = this.injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
|
7880 | return p.then(( |
7881 |
|
7882 |
|
7883 | () => {
|
7884 |
|
7885 | let resolve = ( (null));
|
7886 |
|
7887 | const res = new Promise(( |
7888 |
|
7889 |
|
7890 |
|
7891 | r => resolve = r));
|
7892 |
|
7893 | const router = this.injector.get(Router);
|
7894 |
|
7895 | const opts = this.injector.get(ROUTER_CONFIGURATION);
|
7896 | if (this.isLegacyDisabled(opts) || this.isLegacyEnabled(opts)) {
|
7897 | resolve(true);
|
7898 | }
|
7899 | else if (opts.initialNavigation === 'disabled') {
|
7900 | router.setUpLocationChangeListener();
|
7901 | resolve(true);
|
7902 | }
|
7903 | else if (opts.initialNavigation === 'enabled') {
|
7904 | router.hooks.afterPreactivation = ( |
7905 |
|
7906 |
|
7907 | () => {
|
7908 |
|
7909 | if (!this.initNavigation) {
|
7910 | this.initNavigation = true;
|
7911 | resolve(true);
|
7912 | return this.resultOfPreactivationDone;
|
7913 |
|
7914 | }
|
7915 | else {
|
7916 | return ( (of(null)));
|
7917 | }
|
7918 | });
|
7919 | router.initialNavigation();
|
7920 | }
|
7921 | else {
|
7922 | throw new Error(`Invalid initialNavigation options: '${opts.initialNavigation}'`);
|
7923 | }
|
7924 | return res;
|
7925 | }));
|
7926 | }
|
7927 | |
7928 |
|
7929 |
|
7930 |
|
7931 | bootstrapListener(bootstrappedComponentRef) {
|
7932 |
|
7933 | const opts = this.injector.get(ROUTER_CONFIGURATION);
|
7934 |
|
7935 | const preloader = this.injector.get(RouterPreloader);
|
7936 |
|
7937 | const routerScroller = this.injector.get(RouterScroller);
|
7938 |
|
7939 | const router = this.injector.get(Router);
|
7940 |
|
7941 | const ref = this.injector.get(ApplicationRef);
|
7942 | if (bootstrappedComponentRef !== ref.components[0]) {
|
7943 | return;
|
7944 | }
|
7945 | if (this.isLegacyEnabled(opts)) {
|
7946 | router.initialNavigation();
|
7947 | }
|
7948 | else if (this.isLegacyDisabled(opts)) {
|
7949 | router.setUpLocationChangeListener();
|
7950 | }
|
7951 | preloader.setUpPreloading();
|
7952 | routerScroller.init();
|
7953 | router.resetRootComponentType(ref.componentTypes[0]);
|
7954 | this.resultOfPreactivationDone.next(( (null)));
|
7955 | this.resultOfPreactivationDone.complete();
|
7956 | }
|
7957 | |
7958 |
|
7959 |
|
7960 |
|
7961 |
|
7962 | isLegacyEnabled(opts) {
|
7963 | return opts.initialNavigation === 'legacy_enabled' || opts.initialNavigation === true ||
|
7964 | opts.initialNavigation === undefined;
|
7965 | }
|
7966 | |
7967 |
|
7968 |
|
7969 |
|
7970 |
|
7971 | isLegacyDisabled(opts) {
|
7972 | return opts.initialNavigation === 'legacy_disabled' || opts.initialNavigation === false;
|
7973 | }
|
7974 | }
|
7975 | RouterInitializer.decorators = [
|
7976 | { type: Injectable }
|
7977 | ];
|
7978 |
|
7979 | RouterInitializer.ctorParameters = () => [
|
7980 | { type: Injector }
|
7981 | ];
|
7982 |
|
7983 |
|
7984 |
|
7985 |
|
7986 | function getAppInitializer(r) {
|
7987 | return r.appInitializer.bind(r);
|
7988 | }
|
7989 |
|
7990 |
|
7991 |
|
7992 |
|
7993 | function getBootstrapListener(r) {
|
7994 | return r.bootstrapListener.bind(r);
|
7995 | }
|
7996 |
|
7997 |
|
7998 |
|
7999 |
|
8000 |
|
8001 |
|
8002 |
|
8003 | const ROUTER_INITIALIZER = new InjectionToken('Router Initializer');
|
8004 |
|
8005 |
|
8006 |
|
8007 | function provideRouterInitializer() {
|
8008 | return [
|
8009 | RouterInitializer,
|
8010 | {
|
8011 | provide: APP_INITIALIZER,
|
8012 | multi: true,
|
8013 | useFactory: getAppInitializer,
|
8014 | deps: [RouterInitializer]
|
8015 | },
|
8016 | { provide: ROUTER_INITIALIZER, useFactory: getBootstrapListener, deps: [RouterInitializer] },
|
8017 | { provide: APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER },
|
8018 | ];
|
8019 | }
|
8020 |
|
8021 |
|
8022 |
|
8023 |
|
8024 |
|
8025 |
|
8026 |
|
8027 |
|
8028 |
|
8029 | const VERSION = new Version('8.1.3');
|
8030 |
|
8031 |
|
8032 |
|
8033 |
|
8034 |
|
8035 |
|
8036 |
|
8037 |
|
8038 |
|
8039 |
|
8040 |
|
8041 |
|
8042 |
|
8043 |
|
8044 |
|
8045 |
|
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 |
|
8051 |
|
8052 |
|
8053 |
|
8054 |
|
8055 | export { ɵEmptyOutletComponent as ɵangular_packages_router_router_l, ɵEmptyOutletComponent, ROUTER_FORROOT_GUARD as ɵangular_packages_router_router_a, RouterInitializer as ɵangular_packages_router_router_h, createRouterScroller as ɵangular_packages_router_router_c, getAppInitializer as ɵangular_packages_router_router_i, getBootstrapListener as ɵangular_packages_router_router_j, provideForRootGuard as ɵangular_packages_router_router_e, provideLocationStrategy as ɵangular_packages_router_router_d, provideRouterInitializer as ɵangular_packages_router_router_k, rootRoute as ɵangular_packages_router_router_g, routerNgProbeToken as ɵangular_packages_router_router_b, setupRouter as ɵangular_packages_router_router_f, RouterScroller as ɵangular_packages_router_router_o, Tree as ɵangular_packages_router_router_m, TreeNode as ɵangular_packages_router_router_n, RouterLink, RouterLinkWithHref, RouterLinkActive, RouterOutlet, ActivationEnd, ActivationStart, ChildActivationEnd, ChildActivationStart, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouterEvent, RoutesRecognized, Scroll, RouteReuseStrategy, Router, ROUTES, ROUTER_CONFIGURATION, ROUTER_INITIALIZER, RouterModule, provideRoutes, ChildrenOutletContexts, OutletContext, NoPreloading, PreloadAllModules, PreloadingStrategy, RouterPreloader, ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, PRIMARY_OUTLET, convertToParamMap, UrlHandlingStrategy, DefaultUrlSerializer, UrlSegment, UrlSegmentGroup, UrlSerializer, UrlTree, VERSION, ROUTER_PROVIDERS as ɵROUTER_PROVIDERS, flatten as ɵflatten };
|
8056 |
|