Skip to content

Commit

Permalink
use current pathname when nav to another version
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolee1231 committed Dec 13, 2023
1 parent 939c448 commit 463fc44
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { useEventListener } from '@vueuse/core';
import { useData } from 'vitepress';
import DefaultTheme from 'vitepress/theme';
import { nextTick, provide } from 'vue';
Expand Down Expand Up @@ -37,6 +38,18 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
}
);
});
useEventListener('click', (event) => {
const target = event.target as HTMLAnchorElement;
if (target.tagName.toLowerCase() === 'a' && /v[^\/]*\/$/.test(target.href)) {
event.preventDefault();
const link = `${target.href}${location.pathname
.replace(/^\/v[^\/]*\//, '/')
.slice(1)}`;
window.open(link, target.target);
}
});
</script>

<template>
Expand Down

0 comments on commit 463fc44

Please sign in to comment.