diff --git a/src/.vuepress/client.ts b/src/.vuepress/client.ts index d2b0d35fb..cfe0e3bfd 100644 --- a/src/.vuepress/client.ts +++ b/src/.vuepress/client.ts @@ -19,6 +19,7 @@ import { defineDocSearchConfig } from '@vuepress/plugin-docsearch/client'; import { computed } from 'vue'; import { defineClientConfig, usePageData, useRouter, withBase } from 'vuepress/client'; +import useLegacyRoute from './composables/useLegacyRoute'; import DocSearch from './components/DocSearch.vue'; import { getDocVersion } from './utils/index.js'; @@ -27,6 +28,7 @@ export default defineClientConfig({ app.component('DocSearch', DocSearch); }, setup() { + useLegacyRoute(); const pageData = usePageData(); const router = useRouter(); diff --git a/src/.vuepress/components/Sidevar.vue b/src/.vuepress/components/Sidevar.vue index 1fbedddf0..8d8fc9bb3 100644 --- a/src/.vuepress/components/Sidevar.vue +++ b/src/.vuepress/components/Sidevar.vue @@ -64,17 +64,20 @@ watch( } .switch-list { display: flex; - width: 100px; + text-align: center; + width: 120px; margin-right: 12px; border-radius: 14px; background-color: #f0f1fa; list-style-type: none; padding: 4px; margin: 0; + margin-left: 16px; margin-top: 1rem; .switch-type { padding: 3px 9px; + flex: 1; cursor: pointer; border-radius: 14px; background-color: transparent; diff --git a/src/.vuepress/composables/useLegacyRoute.ts b/src/.vuepress/composables/useLegacyRoute.ts new file mode 100644 index 000000000..3a703639a --- /dev/null +++ b/src/.vuepress/composables/useLegacyRoute.ts @@ -0,0 +1,31 @@ +import { onMounted } from 'vue'; +import { useRoute, withBase } from 'vuepress/client'; +import { getDocVersion } from '../utils/index.js'; + +const useLegacyRoute = () => { + const route = useRoute(); + onMounted(() => { + let lang = 'zh'; + const allPath: string[] = route.path?.split('/'); + if (allPath && allPath.length > 2) { + if ((allPath[0]==='' && allPath[1] === 'zh')||(allPath[0]==='zh')) { + lang = 'zh'; + } else { + lang = ''; + } + } + const version = getDocVersion(route.path, ''); + // 如果路径中包含 Tree 或 Table,并且当前页面内容为 404,则跳转到对应的 Quick Start 页面 + if (version==='latest' || version.includes('-Tree') || version.includes('-Table')) { + if(document.getElementsByClassName('not-found-hint').length>0){ + // 替换 URL 中的 Tree 或 Table 之后的内容为 QuickStart/QuickStart.html + + window.location.href = `${window.location.origin}${withBase(lang+'/UserGuide/'+version+'/QuickStart/QuickStart.html')}`; + //window.location.href = `${window.location.origin}/docs/zh/UserGuide/V2.0.1/${dialect}/QuickStart/QuickStart.html`; + } + } + }); +} + +export default useLegacyRoute; +export { useLegacyRoute }; \ No newline at end of file