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