MCPcopy Create free account
hub / github.com/angular/angular / match

Function match

packages/router/src/utils/config_matching.ts:83–123  ·  view source on GitHub ↗
(
  segmentGroup: UrlSegmentGroup,
  route: Route,
  segments: UrlSegment[],
)

Source from the content-addressed store, hash-verified

81}
82
83export function match(
84 segmentGroup: UrlSegmentGroup,
85 route: Route,
86 segments: UrlSegment[],
87): MatchResult {
88 if (route.path === '') {
89 if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || segments.length > 0)) {
90 return {...noMatch};
91 }
92
93 return {
94 matched: true,
95 consumedSegments: [],
96 remainingSegments: segments,
97 parameters: {},
98 positionalParamSegments: {},
99 };
100 }
101
102 const matcher = route.matcher || defaultUrlMatcher;
103 const res = matcher(segments, segmentGroup, route);
104 if (!res) return {...noMatch};
105
106 const posParams: {[n: string]: string} = {};
107 Object.entries(res.posParams ?? {}).forEach(([k, v]) => {
108 posParams[k] = v.path;
109 });
110 const parameters =
111 res.consumed.length > 0
112 ? {...posParams, ...res.consumed[res.consumed.length - 1].parameters}
113 : posParams;
114
115 return {
116 matched: true,
117 consumedSegments: res.consumed,
118 remainingSegments: segments.slice(res.consumed.length),
119 // TODO(atscott): investigate combining parameters and positionalParamSegments
120 parameters,
121 positionalParamSegments: res.posParams ?? {},
122 };
123}
124
125export function split(
126 segmentGroup: UrlSegmentGroup,

Callers 3

_matchMethod · 0.85
matchWithChecksFunction · 0.85

Calls 5

sliceMethod · 0.65
matcherFunction · 0.50
hasChildrenMethod · 0.45
forEachMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected