Skip to content

Commit 98d15a1

Browse files
authored
refactor(router-core): trimPathRight more performant w/o trailing slash (#5909)
1 parent 823bf66 commit 98d15a1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/router-core/src/path.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export function trimPathLeft(path: string) {
3636
/** Trim trailing slashes (except preserving root '/'). */
3737
/** Trim trailing slashes (except preserving root '/'). */
3838
export function trimPathRight(path: string) {
39-
return path === '/' ? path : path.replace(/\/{1,}$/, '')
39+
const len = path.length
40+
return len > 1 && path[len - 1] === '/' ? path.replace(/\/{1,}$/, '') : path
4041
}
4142

4243
/** Trim both leading and trailing slashes. */

0 commit comments

Comments
 (0)