fix(SW-705): Updated logic for language switcher

This commit is contained in:
Pontus Dreij
2024-11-29 17:03:20 +01:00
parent 9d4c6eb25d
commit 89c131e3eb
6 changed files with 33 additions and 41 deletions

View 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
}