MCPcopy Index your code
hub / github.com/angular/angular-cli / insert

Method insert

packages/angular/ssr/src/routes/route-tree.ts:114–137  ·  view source on GitHub ↗

* Inserts a new route into the route tree. * The route is broken down into segments, and each segment is added to the tree. * Parameterized segments (e.g., :id) are normalized to wildcards (*) for matching purposes. * * @param route - The route path to insert into the tree. * @param m

(route: string, metadata: RouteTreeNodeMetadataWithoutRoute & AdditionalMetadata)

Source from the content-addressed store, hash-verified

112 * @param metadata - Metadata associated with the route, excluding the route path itself.
113 */
114 insert(route: string, metadata: RouteTreeNodeMetadataWithoutRoute & AdditionalMetadata): void {
115 let node = this.root;
116 const segments = this.getPathSegments(route);
117 const normalizedSegments: string[] = [];
118
119 for (const segment of segments) {
120 // Replace parameterized segments (e.g., :id) with a wildcard (*) for matching
121 const normalizedSegment = segment[0] === ':' ? '*' : segment;
122 let childNode = node.children.get(normalizedSegment);
123 if (!childNode) {
124 childNode = this.createEmptyRouteTreeNode();
125 node.children.set(normalizedSegment, childNode);
126 }
127
128 node = childNode;
129 normalizedSegments.push(normalizedSegment);
130 }
131
132 // At the leaf node, store the full route and its associated metadata
133 node.metadata = {
134 ...metadata,
135 route: addLeadingSlash(normalizedSegments.join('/')),
136 };
137 }
138
139 /**
140 * Matches a given route against the route tree and returns the best matching route's metadata.

Callers 5

fromObjectMethod · 0.95
extractFunction · 0.95
route-tree_spec.tsFile · 0.80
handleSSGRouteFunction · 0.80

Calls 6

getPathSegmentsMethod · 0.95
addLeadingSlashFunction · 0.90
getMethod · 0.65
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected