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