fix(SW-705): Updated logic for language switcher
This commit is contained in:
19
components/LanguageSwitcher/LanguageSwitcherContent/utils.ts
Normal file
19
components/LanguageSwitcher/LanguageSwitcherContent/utils.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export function replaceUrlPart(currentPath: string, newPart: string): string {
|
||||
const pathSegments = currentPath.split("/").filter((segment) => segment)
|
||||
|
||||
const newPathSegments = newPart
|
||||
.replace(/\/$/, "")
|
||||
.split("/")
|
||||
.filter((segment) => segment)
|
||||
|
||||
const isFullPathReplacement = newPathSegments.length > 1
|
||||
|
||||
if (isFullPathReplacement) {
|
||||
return `/${newPathSegments.join("/")}`
|
||||
}
|
||||
|
||||
const updatedPathSegments = pathSegments.slice(1)
|
||||
const updatedPath = `/${newPathSegments.concat(updatedPathSegments).join("/")}`
|
||||
|
||||
return updatedPath
|
||||
}
|
||||
Reference in New Issue
Block a user