Fix redirect to right page for content redirects (#2241)

This commit is contained in:
Samy Pessé
2024-03-26 22:30:47 +00:00
committed by GitHub
parent 0ddbe5c0ee
commit 4be6eada62
+16 -10
View File
@@ -570,19 +570,25 @@ async function lookupSpaceByAPI(
if ('redirect' in data) {
if (alternative.primary) {
// Append the path to the redirect URL if it's a VA redirect
// Append the path to the redirect URL
// because we might have matched a shorter path and the redirect is relative to it
if (alternative.extraPath) {
const redirect = new URL(data.redirect);
if (redirect.searchParams.has('location')) {
redirect.searchParams.set(
'location',
joinPath(
redirect.searchParams.get('location') ?? '',
alternative.extraPath,
),
);
if (data.target === 'content') {
const redirect = new URL(data.redirect);
redirect.pathname = joinPath(redirect.pathname, alternative.extraPath);
data.redirect = redirect.toString();
} else {
const redirect = new URL(data.redirect);
if (redirect.searchParams.has('location')) {
redirect.searchParams.set(
'location',
joinPath(
redirect.searchParams.get('location') ?? '',
alternative.extraPath,
),
);
data.redirect = redirect.toString();
}
}
}