mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(router): revert commit that replaced last helper with native Array.at(-1) (#54021)
While `Array.at` is technically supported in all browsers we officially support, the change was needlessly breaking without any real benefit. PR Close #54021
This commit is contained in:
committed by
Pawel Kozlowski
parent
aeaec8629c
commit
bc85551bfc
@@ -1583,6 +1583,9 @@
|
||||
{
|
||||
"name": "last"
|
||||
},
|
||||
{
|
||||
"name": "last3"
|
||||
},
|
||||
{
|
||||
"name": "lastNodeWasCreated"
|
||||
},
|
||||
|
||||
@@ -12,7 +12,7 @@ import {RuntimeErrorCode} from './errors';
|
||||
import {ActivatedRouteSnapshot} from './router_state';
|
||||
import {Params, PRIMARY_OUTLET} from './shared';
|
||||
import {createRoot, squashSegmentGroup, UrlSegment, UrlSegmentGroup, UrlTree} from './url_tree';
|
||||
import {shallowEqual} from './utils/collection';
|
||||
import {last, shallowEqual} from './utils/collection';
|
||||
|
||||
|
||||
/**
|
||||
@@ -187,7 +187,7 @@ class Navigation {
|
||||
}
|
||||
|
||||
const cmdWithOutlet = commands.find(isCommandWithOutlets);
|
||||
if (cmdWithOutlet && cmdWithOutlet !== commands.at(-1)) {
|
||||
if (cmdWithOutlet && cmdWithOutlet !== last(commands)) {
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.MISPLACED_OUTLETS_COMMAND,
|
||||
(typeof ngDevMode === 'undefined' || ngDevMode) &&
|
||||
|
||||
@@ -57,6 +57,13 @@ export function equalArraysOrString(a: string|string[], b: string|string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last element of an array.
|
||||
*/
|
||||
export function last<T>(a: T[]): T|null {
|
||||
return a.length > 0 ? a[a.length - 1] : null;
|
||||
}
|
||||
|
||||
export function wrapIntoObservable<T>(value: T|Promise<T>|Observable<T>): Observable<T> {
|
||||
if (isObservable(value)) {
|
||||
return value;
|
||||
|
||||
@@ -15,6 +15,7 @@ import {runCanMatchGuards} from '../operators/check_guards';
|
||||
import {defaultUrlMatcher, PRIMARY_OUTLET} from '../shared';
|
||||
import {UrlSegment, UrlSegmentGroup, UrlSerializer} from '../url_tree';
|
||||
|
||||
import {last} from './collection';
|
||||
import {getOrCreateRouteInjectorIfNeeded, getOutlet} from './config';
|
||||
|
||||
export interface MatchResult {
|
||||
@@ -95,7 +96,7 @@ export function match(
|
||||
function createWildcardMatchResult(segments: UrlSegment[]): MatchResult {
|
||||
return {
|
||||
matched: true,
|
||||
parameters: segments.at(-1)?.parameters ?? {},
|
||||
parameters: segments.length > 0 ? last(segments)!.parameters : {},
|
||||
consumedSegments: segments,
|
||||
remainingSegments: [],
|
||||
positionalParamSegments: {},
|
||||
|
||||
Reference in New Issue
Block a user