diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index 41aa826..de0a41e 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -13,33 +13,6 @@ import { onMounted, } from 'vue'; -// 兼容旧链接/短链重定向 -if (!import.meta.env.SSR) { - const u = location.href.substring(location.origin.length); - if (location.pathname.startsWith('/selector/')) { - if (location.pathname.at(-1) === '/') { - location.pathname = '/guide/selector'; - } else { - location.pathname = location.pathname.replace('/selector/', '/guide/'); - } - } else if (location.pathname === '/subscription/') { - location.pathname = '/guide/subscription'; - } else if (location.pathname === '/') { - const r = new URLSearchParams(location.search).get('r'); - if (r === '1') { - location.href = '/guide/snapshot#how-to-upload'; - } else if (r === '2') { - location.href = '/guide/faq#restriction'; - } else if (r === '3') { - location.href = '/guide/faq#adb_failed'; - } else if (r === '4') { - location.href = 'https://shizuku.rikka.app'; - } - } else if (u === '/guide/faq#fail_setting_secure_settings') { - location.hash = 'adb_failed'; - } -} - const ScrollbarWrapper = defineComponent(() => { const show = shallowRef(false); onMounted(() => { @@ -62,9 +35,35 @@ export default { Layout() { return h(Fragment, null, [h(DefaultTheme.Layout), h(ScrollbarWrapper)]); }, - enhanceApp({ app }) { + enhanceApp({ app, router }) { Object.entries(components).forEach(([name, component]) => { app.component(name, component); }); + // 兼容旧链接/短链重定向 + if (!import.meta.env.SSR) { + const u = location.href.substring(location.origin.length); + if (location.pathname.startsWith('/selector/')) { + if (location.pathname.at(-1) === '/') { + router.go('/guide/selector'); + } else { + router.go(location.pathname.replace('/selector/', '/guide/')); + } + } else if (location.pathname === '/subscription/') { + router.go('/guide/subscription'); + } else if (location.pathname === '/') { + const r = new URLSearchParams(location.search).get('r'); + if (r === '1') { + router.go('/guide/snapshot#how-to-upload'); + } else if (r === '2') { + router.go('/guide/faq#restriction'); + } else if (r === '3') { + router.go('/guide/faq#adb_failed'); + } else if (r === '4') { + location.href = 'https://shizuku.rikka.app'; + } + } else if (u === '/guide/faq#fail_setting_secure_settings') { + location.hash = 'adb_failed'; + } + } }, } satisfies Theme;