Skip to content

Commit 88f3ed7

Browse files
committed
refactor(router-core): trimPathRight more performant w/o trailing slash
1 parent 37eb416 commit 88f3ed7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

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)