Skip to content

Commit dac31ed

Browse files
committed
fix: url
1 parent 2ff75ad commit dac31ed

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/.vuepress/components/Redirect.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@ export default {
1616
setup(props) {
1717
onMounted(async () => {
1818
await nextTick();
19-
19+
2020
if (typeof window !== 'undefined') {
21+
console.log(props.to);
22+
console.log('window.location', window.location);
23+
24+
// Remove leading/trailing slashes and ensure proper joining
25+
const joinUrl = (base, path) => {
26+
const cleanBase = base.replace(/\/$/, '');
27+
const cleanPath = path.replace(/^\//, '');
28+
return `${cleanBase}/${cleanPath}`;
29+
};
30+
2131
const targetUrl = props.to.endsWith('/') ? props.to : `${props.to}/`;
22-
window.location.replace(targetUrl);
32+
const currentUrl = window.location.href;
33+
34+
window.location.replace(joinUrl(currentUrl, targetUrl));
2335
}
2436
});
25-
37+
2638
return {};
2739
},
2840
};

0 commit comments

Comments
 (0)