fix href reloc

This commit is contained in:
rustdesk
2026-08-14 23:35:52 +08:00
parent 2a09e9a58b
commit d9471c00f6
+13 -1
View File
@@ -131,7 +131,19 @@ metadata.description ||= (t({
}
}
if (lang && lang !== defaultLocale) {
location.href = `${baseUrl + lang + location.pathname + (location.hash || location.search || '')}`.replace(/\/$/, '');
// Localized URLs can differ from prefixed paths (blog post slugs carry a
// language suffix), so prefer the hreflang alternate rendered above.
let target;
document.querySelectorAll('link[rel="alternate"][hreflang]').forEach((link) => {
if (link.getAttribute('hreflang').toLowerCase() === lang) {
target = link.getAttribute('href');
}
});
if (target) {
location.href = target + (location.hash || location.search || '');
} else {
location.href = `${baseUrl + lang + location.pathname + (location.hash || location.search || '')}`.replace(/\/$/, '');
}
}
</script> }
</head>