Skip to content

Commit

Permalink
chore(react-router): undo the comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Oct 25, 2024
1 parent c2c2c8d commit 4c36aab
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/react-router/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,32 +267,37 @@ export function removeBasepath(
pathname: string,
caseSensitive: boolean = false,
) {
// Normalize basepath and pathname for case-insensitive comparison if needed
// normalize basepath and pathname for case-insensitive comparison if needed
const normalizedBasepath = caseSensitive ? basepath : basepath.toLowerCase()
const normalizedPathname = caseSensitive ? pathname : pathname.toLowerCase()

switch (true) {
// Default behaviour when the basepath is root ('/')
// default behaviour is to serve app from the root - pathname
// left untouched
case normalizedBasepath === '/':
return pathname

// Shortcut for removing the basepath if it matches the pathname
// shortcut for removing the basepath if it matches the pathname
case normalizedPathname === normalizedBasepath:
return ''

// If pathname is shorter than basepath, there's nothing to remove
// in case pathname is shorter than basepath - there is
// nothing to remove
case pathname.length < basepath.length:
return pathname

// Avoid matching partial segments
// avoid matching partial segments - strict equality handled
// earlier, otherwise, basepath separated from pathname with
// separator, therefore lack of separator means partial
// segment match (`/app` should not match `/application`)
case normalizedPathname[normalizedBasepath.length] !== '/':
return pathname

// Remove the basepath if the pathname starts with it
// remove the basepath from the pathname if it starts with it
case normalizedPathname.startsWith(normalizedBasepath):
return pathname.slice(basepath.length)

// Otherwise, return the pathname as is
// otherwise, return the pathname as is
default:
return pathname
}
Expand Down

0 comments on commit 4c36aab

Please sign in to comment.