Skip to content

Commit

Permalink
fix(plugin-redirect): fix redirect modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed May 9, 2024
1 parent 8a54cb7 commit d75645c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions plugins/plugin-redirect/src/client/components/RedirectModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
onMounted,
ref,
TransitionGroup,
watch,
} from 'vue'
import { useRoute, useRouteLocale, useRouter } from 'vuepress/client'
import { useRouteLocale, useRoutePath, useRouter } from 'vuepress/client'
import type { RedirectPluginLocaleConfig } from '../../shared/locales.js'
import { redirectLocaleConfig, redirectLocaleEntries } from '../define.js'

Expand All @@ -40,8 +41,8 @@ export default defineComponent({

setup() {
const languages = usePreferredLanguages()
const route = useRoute()
const router = useRouter()
const routePath = useRoutePath()
const routeLocale = useRouteLocale()

const body = ref<HTMLElement>()
Expand Down Expand Up @@ -85,18 +86,21 @@ export default defineComponent({
})

const redirect = (): void => {
if (info.value)
router.replace(
route.path.replace(routeLocale.value, info.value.localePath),
)
router.replace(
routePath.value.replace(routeLocale.value, info.value!.localePath),
)
}

watch(routePath, () => {
showModal.value = false
})

onMounted(async () => {
body.value = document.body

await nextTick()

if (!redirectStatusStorage.value[routeLocale.value]) {
if (!redirectStatusStorage.value[routeLocale.value] && info.value) {
if (switchLocale === 'direct') redirect()
else if (switchLocale === 'modal') showModal.value = true
}
Expand Down

0 comments on commit d75645c

Please sign in to comment.