Merged in feat/SW-1296-hotel-subpages (pull request #1233)
feat(SW-1296): added Subpage for hotel pages and its routing * feat(SW-1296): added Subpage for hotel pages and its routing Approved-by: Fredrik Thorsson
This commit is contained in:
@@ -29,6 +29,7 @@ export default function Link({
|
||||
* Decides if the link should include the current search params in the URL
|
||||
*/
|
||||
keepSearchParams,
|
||||
appendToCurrentPath,
|
||||
...props
|
||||
}: LinkProps) {
|
||||
const currentPageSlug = usePathname()
|
||||
@@ -50,11 +51,24 @@ export default function Link({
|
||||
})
|
||||
|
||||
const fullUrl = useMemo(() => {
|
||||
if (!keepSearchParams || !searchParams.size) return href
|
||||
let newPath = href
|
||||
if (appendToCurrentPath) {
|
||||
newPath = `${currentPageSlug}${newPath}`
|
||||
}
|
||||
|
||||
const delimiter = href.includes("?") ? "&" : "?"
|
||||
return `${href}${delimiter}${searchParams}`
|
||||
}, [href, searchParams, keepSearchParams])
|
||||
if (keepSearchParams && searchParams.size) {
|
||||
const delimiter = newPath.includes("?") ? "&" : "?"
|
||||
return `${newPath}${delimiter}${searchParams}`
|
||||
}
|
||||
|
||||
return newPath
|
||||
}, [
|
||||
href,
|
||||
searchParams,
|
||||
keepSearchParams,
|
||||
appendToCurrentPath,
|
||||
currentPageSlug,
|
||||
])
|
||||
|
||||
// TODO: Remove this check (and hook) and only return <Link /> when current web is deleted
|
||||
const isExternal = useCheckIfExternalLink(href)
|
||||
|
||||
@@ -12,4 +12,5 @@ export interface LinkProps
|
||||
trackingId?: string
|
||||
trackingParams?: Record<string, string>
|
||||
keepSearchParams?: boolean
|
||||
appendToCurrentPath?: boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user