Skip to content

Commit

Permalink
fix: router
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Dec 4, 2024
1 parent a7d05c6 commit dc0d58d
Showing 1 changed file with 44 additions and 35 deletions.
79 changes: 44 additions & 35 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import 'uno.css';
import type { Theme } from 'vitepress';
import { useRouter, type Theme } from 'vitepress';
import DefaultTheme from 'vitepress/theme';
import components from '../components';
import BodyScrollbar from '../components/BodyScrollbar.vue';
import './custom.css';
import {
defineComponent,
Fragment,
h,
Teleport,
defineComponent,
shallowRef,
onMounted,
shallowRef,
Teleport,
} from 'vue';
import components from '../components';
import BodyScrollbar from '../components/BodyScrollbar.vue';
import './custom.css';

const ScrollbarWrapper = defineComponent(() => {
const show = shallowRef(false);
Expand All @@ -30,40 +30,49 @@ const ScrollbarWrapper = defineComponent(() => {
};
});

const Redirect = defineComponent(() => {
const router = useRouter();
onMounted(() => {
// 兼容旧链接/短链重定向
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';
}
});
return () => {};
});

export default {
extends: DefaultTheme,
Layout() {
return h(Fragment, null, [h(DefaultTheme.Layout), h(ScrollbarWrapper)]);
return h(Fragment, null, [
h(DefaultTheme.Layout),
h(ScrollbarWrapper),
h(Redirect),
]);
},
enhanceApp({ app, router }) {
enhanceApp({ app }) {
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;

0 comments on commit dc0d58d

Please sign in to comment.