6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { stripTrailingSlash } from '../utils/url' ;
9
+ import { addLeadingSlash } from '../utils/url' ;
10
10
import { RenderMode } from './route-config' ;
11
11
12
12
/**
@@ -116,7 +116,7 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
116
116
* The root node of the route tree.
117
117
* All routes are stored and accessed relative to this root node.
118
118
*/
119
- private readonly root = this . createEmptyRouteTreeNode ( '' ) ;
119
+ private readonly root = this . createEmptyRouteTreeNode ( '<root> ' ) ;
120
120
121
121
/**
122
122
* A counter that tracks the order of route insertion.
@@ -155,7 +155,7 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
155
155
// At the leaf node, store the full route and its associated metadata
156
156
node . metadata = {
157
157
...metadata ,
158
- route : normalizedSegments . join ( '/' ) ,
158
+ route : addLeadingSlash ( normalizedSegments . join ( '/' ) ) ,
159
159
} ;
160
160
161
161
node . insertionIndex = this . insertionIndexCounter ++ ;
@@ -230,7 +230,7 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
230
230
* @returns An array of path segments.
231
231
*/
232
232
private getPathSegments ( route : string ) : string [ ] {
233
- return stripTrailingSlash ( route ) . split ( '/' ) ;
233
+ return route . split ( '/' ) . filter ( Boolean ) ;
234
234
}
235
235
236
236
/**
@@ -246,18 +246,14 @@ export class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}>
246
246
* @returns The node that best matches the remaining segments or `undefined` if no match is found.
247
247
*/
248
248
private traverseBySegments (
249
- remainingSegments : string [ ] | undefined ,
249
+ remainingSegments : string [ ] ,
250
250
node = this . root ,
251
251
) : RouteTreeNode < AdditionalMetadata > | undefined {
252
252
const { metadata, children } = node ;
253
253
254
254
// 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 ( '**' ) ;
261
257
}
262
258
263
259
// If the node has no children, end the traversal
0 commit comments