66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { stripTrailingSlash } from '../utils/url' ;
9+ import { addLeadingSlash } from '../utils/url' ;
1010import { RenderMode } from './route-config' ;
1111
1212/**
@@ -116,7 +116,7 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
116116 * The root node of the route tree.
117117 * All routes are stored and accessed relative to this root node.
118118 */
119- private readonly root = this . createEmptyRouteTreeNode ( '' ) ;
119+ private readonly root = this . createEmptyRouteTreeNode ( '<root> ' ) ;
120120
121121 /**
122122 * A counter that tracks the order of route insertion.
@@ -155,7 +155,7 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
155155 // At the leaf node, store the full route and its associated metadata
156156 node . metadata = {
157157 ...metadata ,
158- route : normalizedSegments . join ( '/' ) ,
158+ route : addLeadingSlash ( normalizedSegments . join ( '/' ) ) ,
159159 } ;
160160
161161 node . insertionIndex = this . insertionIndexCounter ++ ;
@@ -230,7 +230,7 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
230230 * @returns An array of path segments.
231231 */
232232 private getPathSegments ( route : string ) : string [ ] {
233- return stripTrailingSlash ( route ) . split ( '/' ) ;
233+ return route . split ( '/' ) . filter ( Boolean ) ;
234234 }
235235
236236 /**
@@ -246,18 +246,14 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
246246 * @returns The node that best matches the remaining segments or `undefined` if no match is found.
247247 */
248248 private traverseBySegments (
249- remainingSegments : string [ ] | undefined ,
249+ remainingSegments : string [ ] ,
250250 node = this . root ,
251251 ) : RouteTreeNode < AdditionalMetadata > | undefined {
252252 const { metadata, children } = node ;
253253
254254 // If there are no remaining segments and the node has metadata, return this node
255- if ( ! remainingSegments ?. length ) {
256- if ( metadata ) {
257- return node ;
258- }
259-
260- return ;
255+ if ( ! remainingSegments . length ) {
256+ return metadata ? node : node . children . get ( '**' ) ;
261257 }
262258
263259 // If the node has no children, end the traversal
0 commit comments