@angular/router 11.1.0-next.4 → 11.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/bundles/router-testing.umd.js +1 -1
  2. package/bundles/router-testing.umd.min.js +1 -1
  3. package/bundles/router-testing.umd.min.js.map +1 -1
  4. package/bundles/router-upgrade.umd.js +1 -1
  5. package/bundles/router-upgrade.umd.min.js +1 -1
  6. package/bundles/router-upgrade.umd.min.js.map +1 -1
  7. package/bundles/router.umd.js +108 -98
  8. package/bundles/router.umd.js.map +1 -1
  9. package/bundles/router.umd.min.js +19 -18
  10. package/bundles/router.umd.min.js.map +1 -1
  11. package/esm2015/src/apply_redirects.js +4 -3
  12. package/esm2015/src/create_url_tree.js +2 -2
  13. package/esm2015/src/directives/router_link_active.js +3 -5
  14. package/esm2015/src/events.js +2 -2
  15. package/esm2015/src/operators/activate_routes.js +13 -11
  16. package/esm2015/src/operators/apply_redirects.js +3 -5
  17. package/esm2015/src/operators/check_guards.js +16 -26
  18. package/esm2015/src/operators/prioritized_guard_value.js +2 -2
  19. package/esm2015/src/operators/recognize.js +3 -5
  20. package/esm2015/src/operators/resolve_data.js +10 -12
  21. package/esm2015/src/operators/switch_tap.js +9 -11
  22. package/esm2015/src/router.js +7 -11
  23. package/esm2015/src/router_config_loader.js +7 -3
  24. package/esm2015/src/router_module.js +1 -1
  25. package/esm2015/src/router_state.js +20 -2
  26. package/esm2015/src/url_tree.js +1 -1
  27. package/esm2015/src/utils/collection.js +5 -7
  28. package/esm2015/src/version.js +1 -1
  29. package/fesm2015/router.js +92 -93
  30. package/fesm2015/router.js.map +1 -1
  31. package/fesm2015/testing.js +1 -1
  32. package/fesm2015/upgrade.js +1 -1
  33. package/package.json +4 -4
  34. package/router.d.ts +27 -6
  35. package/router.metadata.json +1 -1
  36. package/testing/testing.d.ts +1 -1
  37. package/testing.d.ts +1 -1
  38. package/upgrade/upgrade.d.ts +1 -1
  39. package/upgrade.d.ts +1 -1
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @license Angular v11.1.0-next.4
2
+ * @license Angular v11.1.1
3
3
  * (c) 2010-2020 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
7
  import { Location, LocationStrategy, ViewportScroller, PlatformLocation, APP_BASE_HREF, HashLocationStrategy, PathLocationStrategy, ɵgetDOM, LOCATION_INITIALIZED } from '@angular/common';
8
- import { ɵisObservable, ɵisPromise, Component, NgModuleRef, InjectionToken, NgModuleFactory, ɵConsole, NgZone, Injectable, Type, Injector, NgModuleFactoryLoader, Compiler, Directive, Attribute, Renderer2, ElementRef, Input, HostListener, HostBinding, ChangeDetectorRef, Optional, ContentChildren, EventEmitter, ViewContainerRef, ComponentFactoryResolver, Output, SystemJsNgModuleLoader, NgProbeToken, ANALYZE_FOR_ENTRY_COMPONENTS, SkipSelf, Inject, APP_INITIALIZER, APP_BOOTSTRAP_LISTENER, NgModule, ApplicationRef, Version } from '@angular/core';
9
- import { from, of, BehaviorSubject, combineLatest, Observable, EmptyError, defer, EMPTY, Subject } from 'rxjs';
10
- import { map, switchMap, take, startWith, scan, filter, catchError, concatMap, last as last$1, first, mergeMap, tap, concatAll, takeLast, finalize, mergeAll } from 'rxjs/operators';
8
+ import { ɵisObservable, ɵisPromise, Component, NgModuleRef, InjectionToken, InjectFlags, NgModuleFactory, ɵConsole, NgZone, Injectable, Type, Injector, NgModuleFactoryLoader, Compiler, Directive, Attribute, Renderer2, ElementRef, Input, HostListener, HostBinding, ChangeDetectorRef, Optional, ContentChildren, EventEmitter, ViewContainerRef, ComponentFactoryResolver, Output, SystemJsNgModuleLoader, NgProbeToken, ANALYZE_FOR_ENTRY_COMPONENTS, SkipSelf, Inject, APP_INITIALIZER, APP_BOOTSTRAP_LISTENER, NgModule, ApplicationRef, Version } from '@angular/core';
9
+ import { from, of, BehaviorSubject, combineLatest, Observable, EmptyError, concat, defer, EMPTY, Subject } from 'rxjs';
10
+ import { map, switchMap, take, startWith, scan, filter, catchError, concatMap, last as last$1, first, mergeMap, tap, takeLast, finalize, mergeAll } from 'rxjs/operators';
11
11
 
12
12
  /**
13
13
  * @license
@@ -227,7 +227,7 @@ class GuardsCheckEnd extends RouterEvent {
227
227
  }
228
228
  }
229
229
  /**
230
- * An event triggered at the the start of the Resolve phase of routing.
230
+ * An event triggered at the start of the Resolve phase of routing.
231
231
  *
232
232
  * Runs in the "resolve" phase whether or not there is anything to resolve.
233
233
  * In future, may change to only run when there are things to be resolved.
@@ -513,12 +513,10 @@ function shallowEqualArrays(a, b) {
513
513
  return true;
514
514
  }
515
515
  function shallowEqual(a, b) {
516
- // Casting Object.keys return values to include `undefined` as there are some cases
517
- // in IE 11 where this can happen. Cannot provide a test because the behavior only
518
- // exists in certain circumstances in IE 11, therefore doing this cast ensures the
519
- // logic is correct for when this edge case is hit.
520
- const k1 = Object.keys(a);
521
- const k2 = Object.keys(b);
516
+ // While `undefined` should never be possible, it would sometimes be the case in IE 11
517
+ // and pre-chromium Edge. The check below accounts for this edge case.
518
+ const k1 = a ? Object.keys(a) : undefined;
519
+ const k2 = b ? Object.keys(b) : undefined;
522
520
  if (!k1 || !k2 || k1.length != k2.length) {
523
521
  return false;
524
522
  }
@@ -1458,7 +1456,25 @@ class ActivatedRouteSnapshot {
1458
1456
  constructor(
1459
1457
  /** The URL segments matched by this route */
1460
1458
  url,
1461
- /** The matrix parameters scoped to this route */
1459
+ /**
1460
+ * The matrix parameters scoped to this route.
1461
+ *
1462
+ * You can compute all params (or data) in the router state or to get params outside
1463
+ * of an activated component by traversing the `RouterState` tree as in the following
1464
+ * example:
1465
+ * ```
1466
+ * collectRouteParams(router: Router) {
1467
+ * let params = {};
1468
+ * let stack: ActivatedRouteSnapshot[] = [router.routerState.snapshot.root];
1469
+ * while (stack.length > 0) {
1470
+ * const route = stack.pop()!;
1471
+ * params = {...params, ...route.params};
1472
+ * stack.push(...route.children);
1473
+ * }
1474
+ * return params;
1475
+ * }
1476
+ * ```
1477
+ */
1462
1478
  params,
1463
1479
  /** The query parameters shared by all the routes */
1464
1480
  queryParams,
@@ -1922,7 +1938,7 @@ function createNewSegmentGroup(segmentGroup, startIndex, commands) {
1922
1938
  // if we start with an object literal, we need to reuse the path part from the segment
1923
1939
  if (i === 0 && isMatrixParams(commands[0])) {
1924
1940
  const p = segmentGroup.segments[startIndex];
1925
- paths.push(new UrlSegment(p.path, commands[0]));
1941
+ paths.push(new UrlSegment(p.path, stringify(commands[0])));
1926
1942
  i++;
1927
1943
  continue;
1928
1944
  }
@@ -2042,16 +2058,18 @@ class ActivateRoutes {
2042
2058
  }
2043
2059
  deactivateRouteAndOutlet(route, parentContexts) {
2044
2060
  const context = parentContexts.getContext(route.value.outlet);
2045
- if (context) {
2046
- const children = nodeChildrenAsMap(route);
2047
- const contexts = route.value.component ? context.children : parentContexts;
2048
- forEach(children, (v, k) => this.deactivateRouteAndItsChildren(v, contexts));
2049
- if (context.outlet) {
2050
- // Destroy the component
2051
- context.outlet.deactivate();
2052
- // Destroy the contexts for all the outlets that were in the component
2053
- context.children.onOutletDeactivated();
2054
- }
2061
+ // The context could be `null` if we are on a componentless route but there may still be
2062
+ // children that need deactivating.
2063
+ const contexts = context && route.value.component ? context.children : parentContexts;
2064
+ const children = nodeChildrenAsMap(route);
2065
+ for (const childOutlet of Object.keys(children)) {
2066
+ this.deactivateRouteAndItsChildren(children[childOutlet], contexts);
2067
+ }
2068
+ if (context && context.outlet) {
2069
+ // Destroy the component
2070
+ context.outlet.deactivate();
2071
+ // Destroy the contexts for all the outlets that were in the component
2072
+ context.children.onOutletDeactivated();
2055
2073
  }
2056
2074
  }
2057
2075
  activateChildRoutes(futureNode, currNode, contexts) {
@@ -2199,7 +2217,7 @@ function isCanDeactivate(guard) {
2199
2217
  const INITIAL_VALUE = Symbol('INITIAL_VALUE');
2200
2218
  function prioritizedGuardValue() {
2201
2219
  return switchMap(obs => {
2202
- return combineLatest(...obs.map(o => o.pipe(take(1), startWith(INITIAL_VALUE))))
2220
+ return combineLatest(obs.map(o => o.pipe(take(1), startWith(INITIAL_VALUE))))
2203
2221
  .pipe(scan((acc, list) => {
2204
2222
  let isPending = false;
2205
2223
  return list.reduce((innerAcc, val, i) => {
@@ -2626,7 +2644,7 @@ class ApplyRedirects {
2626
2644
  return from(childOutlets)
2627
2645
  .pipe(concatMap(childOutlet => {
2628
2646
  const child = segmentGroup.children[childOutlet];
2629
- // Sort the routes so routes with outlets that match the the segment appear
2647
+ // Sort the routes so routes with outlets that match the segment appear
2630
2648
  // first, followed by routes for other outlets, which might match if they have an
2631
2649
  // empty path.
2632
2650
  const sortedRoutes = sortByMatchingOutlets(routes, childOutlet);
@@ -2868,7 +2886,8 @@ function mergeTrivialChildren(s) {
2868
2886
  */
2869
2887
  function squashSegmentGroup(segmentGroup) {
2870
2888
  const newChildren = {};
2871
- for (const [childOutlet, child] of Object.entries(segmentGroup.children)) {
2889
+ for (const childOutlet of Object.keys(segmentGroup.children)) {
2890
+ const child = segmentGroup.children[childOutlet];
2872
2891
  const childCandidate = squashSegmentGroup(child);
2873
2892
  // don't add empty children
2874
2893
  if (childCandidate.segments.length > 0 || childCandidate.hasChildren()) {
@@ -2887,10 +2906,8 @@ function squashSegmentGroup(segmentGroup) {
2887
2906
  * found in the LICENSE file at https://angular.io/license
2888
2907
  */
2889
2908
  function applyRedirects$1(moduleInjector, configLoader, urlSerializer, config) {
2890
- return function (source) {
2891
- return source.pipe(switchMap(t => applyRedirects(moduleInjector, configLoader, urlSerializer, t.extractedUrl, config)
2892
- .pipe(map(urlAfterRedirects => (Object.assign(Object.assign({}, t), { urlAfterRedirects }))))));
2893
- };
2909
+ return switchMap(t => applyRedirects(moduleInjector, configLoader, urlSerializer, t.extractedUrl, config)
2910
+ .pipe(map(urlAfterRedirects => (Object.assign(Object.assign({}, t), { urlAfterRedirects })))));
2894
2911
  }
2895
2912
 
2896
2913
  /**
@@ -3051,20 +3068,18 @@ function deactivateRouteAndItsChildren(route, context, checks) {
3051
3068
  * found in the LICENSE file at https://angular.io/license
3052
3069
  */
3053
3070
  function checkGuards(moduleInjector, forwardEvent) {
3054
- return function (source) {
3055
- return source.pipe(mergeMap(t => {
3056
- const { targetSnapshot, currentSnapshot, guards: { canActivateChecks, canDeactivateChecks } } = t;
3057
- if (canDeactivateChecks.length === 0 && canActivateChecks.length === 0) {
3058
- return of(Object.assign(Object.assign({}, t), { guardsResult: true }));
3059
- }
3060
- return runCanDeactivateChecks(canDeactivateChecks, targetSnapshot, currentSnapshot, moduleInjector)
3061
- .pipe(mergeMap(canDeactivate => {
3062
- return canDeactivate && isBoolean(canDeactivate) ?
3063
- runCanActivateChecks(targetSnapshot, canActivateChecks, moduleInjector, forwardEvent) :
3064
- of(canDeactivate);
3065
- }), map(guardsResult => (Object.assign(Object.assign({}, t), { guardsResult }))));
3066
- }));
3067
- };
3071
+ return mergeMap(t => {
3072
+ const { targetSnapshot, currentSnapshot, guards: { canActivateChecks, canDeactivateChecks } } = t;
3073
+ if (canDeactivateChecks.length === 0 && canActivateChecks.length === 0) {
3074
+ return of(Object.assign(Object.assign({}, t), { guardsResult: true }));
3075
+ }
3076
+ return runCanDeactivateChecks(canDeactivateChecks, targetSnapshot, currentSnapshot, moduleInjector)
3077
+ .pipe(mergeMap(canDeactivate => {
3078
+ return canDeactivate && isBoolean(canDeactivate) ?
3079
+ runCanActivateChecks(targetSnapshot, canActivateChecks, moduleInjector, forwardEvent) :
3080
+ of(canDeactivate);
3081
+ }), map(guardsResult => (Object.assign(Object.assign({}, t), { guardsResult }))));
3082
+ });
3068
3083
  }
3069
3084
  function runCanDeactivateChecks(checks, futureRSS, currRSS, moduleInjector) {
3070
3085
  return from(checks).pipe(mergeMap(check => runCanDeactivate(check.component, check.route, currRSS, futureRSS, moduleInjector)), first(result => {
@@ -3073,15 +3088,7 @@ function runCanDeactivateChecks(checks, futureRSS, currRSS, moduleInjector) {
3073
3088
  }
3074
3089
  function runCanActivateChecks(futureSnapshot, checks, moduleInjector, forwardEvent) {
3075
3090
  return from(checks).pipe(concatMap((check) => {
3076
- return from([
3077
- fireChildActivationStart(check.route.parent, forwardEvent),
3078
- fireActivationStart(check.route, forwardEvent),
3079
- runCanActivateChild(futureSnapshot, check.path, moduleInjector),
3080
- runCanActivate(futureSnapshot, check.route, moduleInjector)
3081
- ])
3082
- .pipe(concatAll(), first(result => {
3083
- return result !== true;
3084
- }, true));
3091
+ return concat(fireChildActivationStart(check.route.parent, forwardEvent), fireActivationStart(check.route, forwardEvent), runCanActivateChild(futureSnapshot, check.path, moduleInjector), runCanActivate(futureSnapshot, check.route, moduleInjector));
3085
3092
  }), first(result => {
3086
3093
  return result !== true;
3087
3094
  }, true));
@@ -3436,10 +3443,8 @@ function getResolve(route) {
3436
3443
  * found in the LICENSE file at https://angular.io/license
3437
3444
  */
3438
3445
  function recognize$1(rootComponentType, config, serializer, paramsInheritanceStrategy, relativeLinkResolution) {
3439
- return function (source) {
3440
- return source.pipe(mergeMap(t => recognize(rootComponentType, config, t.urlAfterRedirects, serializer(t.urlAfterRedirects), paramsInheritanceStrategy, relativeLinkResolution)
3441
- .pipe(map(targetSnapshot => (Object.assign(Object.assign({}, t), { targetSnapshot }))))));
3442
- };
3446
+ return mergeMap(t => recognize(rootComponentType, config, t.urlAfterRedirects, serializer(t.urlAfterRedirects), paramsInheritanceStrategy, relativeLinkResolution)
3447
+ .pipe(map(targetSnapshot => (Object.assign(Object.assign({}, t), { targetSnapshot })))));
3443
3448
  }
3444
3449
 
3445
3450
  /**
@@ -3450,17 +3455,15 @@ function recognize$1(rootComponentType, config, serializer, paramsInheritanceStr
3450
3455
  * found in the LICENSE file at https://angular.io/license
3451
3456
  */
3452
3457
  function resolveData(paramsInheritanceStrategy, moduleInjector) {
3453
- return function (source) {
3454
- return source.pipe(mergeMap(t => {
3455
- const { targetSnapshot, guards: { canActivateChecks } } = t;
3456
- if (!canActivateChecks.length) {
3457
- return of(t);
3458
- }
3459
- let canActivateChecksResolved = 0;
3460
- return from(canActivateChecks)
3461
- .pipe(concatMap(check => runResolve(check.route, targetSnapshot, paramsInheritanceStrategy, moduleInjector)), tap(() => canActivateChecksResolved++), takeLast(1), mergeMap(_ => canActivateChecksResolved === canActivateChecks.length ? of(t) : EMPTY));
3462
- }));
3463
- };
3458
+ return mergeMap(t => {
3459
+ const { targetSnapshot, guards: { canActivateChecks } } = t;
3460
+ if (!canActivateChecks.length) {
3461
+ return of(t);
3462
+ }
3463
+ let canActivateChecksResolved = 0;
3464
+ return from(canActivateChecks)
3465
+ .pipe(concatMap(check => runResolve(check.route, targetSnapshot, paramsInheritanceStrategy, moduleInjector)), tap(() => canActivateChecksResolved++), takeLast(1), mergeMap(_ => canActivateChecksResolved === canActivateChecks.length ? of(t) : EMPTY));
3466
+ });
3464
3467
  }
3465
3468
  function runResolve(futureARS, futureRSS, paramsInheritanceStrategy, moduleInjector) {
3466
3469
  const resolve = futureARS._resolve;
@@ -3509,15 +3512,13 @@ function getResolver(injectionToken, futureARS, futureRSS, moduleInjector) {
3509
3512
  * it will wait before continuing with the original value.
3510
3513
  */
3511
3514
  function switchTap(next) {
3512
- return function (source) {
3513
- return source.pipe(switchMap(v => {
3514
- const nextResult = next(v);
3515
- if (nextResult) {
3516
- return from(nextResult).pipe(map(() => v));
3517
- }
3518
- return from([v]);
3519
- }));
3520
- };
3515
+ return switchMap(v => {
3516
+ const nextResult = next(v);
3517
+ if (nextResult) {
3518
+ return from(nextResult).pipe(map(() => v));
3519
+ }
3520
+ return of(v);
3521
+ });
3521
3522
  }
3522
3523
 
3523
3524
  /**
@@ -3615,7 +3616,11 @@ class RouterConfigLoader {
3615
3616
  this.onLoadEndListener(route);
3616
3617
  }
3617
3618
  const module = factory.create(parentInjector);
3618
- return new LoadedRouterConfig(flatten(module.injector.get(ROUTES)).map(standardizeConfig), module);
3619
+ // When loading a module that doesn't provide `RouterModule.forChild()` preloader will get
3620
+ // stuck in an infinite loop. The child module's Injector will look to its parent `Injector`
3621
+ // when it doesn't find any ROUTES so it will return routes for it's parent module instead.
3622
+ return new LoadedRouterConfig(flatten(module.injector.get(ROUTES, undefined, InjectFlags.Self | InjectFlags.Optional))
3623
+ .map(standardizeConfig), module);
3619
3624
  }));
3620
3625
  }
3621
3626
  loadModuleFactory(loadChildren) {
@@ -3862,7 +3867,7 @@ class Router {
3862
3867
  this.ngModule = injector.get(NgModuleRef);
3863
3868
  this.console = injector.get(ɵConsole);
3864
3869
  const ngZone = injector.get(NgZone);
3865
- this.isNgZoneEnabled = ngZone instanceof NgZone;
3870
+ this.isNgZoneEnabled = ngZone instanceof NgZone && NgZone.isInAngularZone();
3866
3871
  this.resetConfig(config);
3867
3872
  this.currentUrlTree = createEmptyUrlTree();
3868
3873
  this.rawUrlTree = this.currentUrlTree;
@@ -3927,11 +3932,10 @@ class Router {
3927
3932
  if (transition !== this.transitions.getValue()) {
3928
3933
  return EMPTY;
3929
3934
  }
3930
- return [t];
3935
+ // This delay is required to match old behavior that forced
3936
+ // navigation to always be async
3937
+ return Promise.resolve(t);
3931
3938
  }),
3932
- // This delay is required to match old behavior that forced navigation
3933
- // to always be async
3934
- switchMap(t => Promise.resolve(t)),
3935
3939
  // ApplyRedirects
3936
3940
  applyRedirects$1(this.ngModule.injector, this.configLoader, this.urlSerializer, this.config),
3937
3941
  // Update the currentNavigation
@@ -3948,9 +3952,7 @@ class Router {
3948
3952
  }
3949
3953
  this.browserUrlTree = t.urlAfterRedirects;
3950
3954
  }
3951
- }),
3952
- // Fire RoutesRecognized
3953
- tap(t => {
3955
+ // Fire RoutesRecognized
3954
3956
  const routesRecognized = new RoutesRecognized(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
3955
3957
  eventsSubject.next(routesRecognized);
3956
3958
  }));
@@ -4002,7 +4004,6 @@ class Router {
4002
4004
  error.url = t.guardsResult;
4003
4005
  throw error;
4004
4006
  }
4005
- }), tap(t => {
4006
4007
  const guardsEnd = new GuardsCheckEnd(t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot, !!t.guardsResult);
4007
4008
  this.triggerEvent(guardsEnd);
4008
4009
  }), filter(t => {
@@ -4135,7 +4136,7 @@ class Router {
4135
4136
  skipLocationChange: t.extras.skipLocationChange,
4136
4137
  replaceUrl: this.urlUpdateStrategy === 'eager'
4137
4138
  };
4138
- return this.scheduleNavigation(mergedTree, 'imperative', null, extras, { resolve: t.resolve, reject: t.reject, promise: t.promise });
4139
+ this.scheduleNavigation(mergedTree, 'imperative', null, extras, { resolve: t.resolve, reject: t.reject, promise: t.promise });
4139
4140
  }, 0);
4140
4141
  }
4141
4142
  /* All other errors should reset to the router's internal URL reference to
@@ -4883,7 +4884,7 @@ function attrBoolValue(s) {
4883
4884
  * is active.
4884
4885
  *
4885
4886
  * Use this directive to create a visual distinction for elements associated with an active route.
4886
- * For example, the following code highlights the word "Bob" when the the router
4887
+ * For example, the following code highlights the word "Bob" when the router
4887
4888
  * activates the associated route:
4888
4889
  *
4889
4890
  * ```
@@ -4953,9 +4954,7 @@ class RouterLinkActive {
4953
4954
  /** @nodoc */
4954
4955
  ngAfterContentInit() {
4955
4956
  // `of(null)` is used to force subscribe body to execute once immediately (like `startWith`).
4956
- from([this.links.changes, this.linksWithHrefs.changes, of(null)])
4957
- .pipe(mergeAll())
4958
- .subscribe(_ => {
4957
+ of(this.links.changes, this.linksWithHrefs.changes, of(null)).pipe(mergeAll()).subscribe(_ => {
4959
4958
  this.update();
4960
4959
  this.subscribeToEachLinkOnChanges();
4961
4960
  });
@@ -5780,7 +5779,7 @@ function provideRouterInitializer() {
5780
5779
  /**
5781
5780
  * @publicApi
5782
5781
  */
5783
- const VERSION = new Version('11.1.0-next.4');
5782
+ const VERSION = new Version('11.1.1');
5784
5783
 
5785
5784
  /**
5786
5785
  * @license