MCPcopy Index your code
hub / github.com/angular/angular / defaultUrlMatcher

Function defaultUrlMatcher

packages/router/src/shared.ts:153–218  ·  view source on GitHub ↗
(
  segments: UrlSegment[],
  segmentGroup: UrlSegmentGroup,
  route: Route,
)

Source from the content-addressed store, hash-verified

151 * @publicApi
152 */
153export function defaultUrlMatcher(
154 segments: UrlSegment[],
155 segmentGroup: UrlSegmentGroup,
156 route: Route,
157): UrlMatchResult | null {
158 const parts = route.path!.split('/');
159 const wildcardIndex = parts.indexOf('**');
160 if (wildcardIndex === -1) {
161 // No wildcard, use original logic
162 if (parts.length > segments.length) {
163 // The actual URL is shorter than the config, no match
164 return null;
165 }
166
167 if (
168 route.pathMatch === 'full' &&
169 (segmentGroup.hasChildren() || parts.length < segments.length)
170 ) {
171 // The config is longer than the actual URL but we are looking for a full match, return null
172 return null;
173 }
174
175 const posParams: {[key: string]: UrlSegment} = {};
176 const consumed = segments.slice(0, parts.length);
177 if (!matchParts(parts, consumed, posParams)) {
178 return null;
179 }
180 return {consumed, posParams};
181 }
182
183 // Path has a wildcard.
184 if (wildcardIndex !== parts.lastIndexOf('**')) {
185 // We do not support more than one wildcard segment in the path
186 return null;
187 }
188
189 const pre = parts.slice(0, wildcardIndex);
190 const post = parts.slice(wildcardIndex + 1);
191
192 if (pre.length + post.length > segments.length) {
193 // The actual URL is shorter than the config, no match
194 return null;
195 }
196
197 if (route.pathMatch === 'full' && segmentGroup.hasChildren() && route.path !== '**') {
198 // The config is longer than the actual URL but we are looking for a full match, return null
199 return null;
200 }
201
202 const posParams: {[key: string]: UrlSegment} = {};
203
204 // Match the segments before the wildcard
205 if (!matchParts(pre, segments.slice(0, pre.length), posParams)) {
206 return null;
207 }
208 // Match the segments after the wildcard
209 if (!matchParts(post, segments.slice(segments.length - post.length), posParams)) {
210 return null;

Callers

nothing calls this directly

Calls 3

matchPartsFunction · 0.85
indexOfMethod · 0.80
hasChildrenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…