Skip to content

Commit 4618f66

Browse files
committed
fix 404
1 parent 44abc15 commit 4618f66

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/.vuepress/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import { defineDocSearchConfig } from '@vuepress/plugin-docsearch/client';
2020
import { computed } from 'vue';
2121
import { defineClientConfig, usePageData, useRouter, withBase } from 'vuepress/client';
22+
import useLegacyRoute from './composables/useLegacyRoute';
2223
import DocSearch from './components/DocSearch.vue';
2324
import { getDocVersion } from './utils/index.js';
2425

@@ -27,6 +28,7 @@ export default defineClientConfig({
2728
app.component('DocSearch', DocSearch);
2829
},
2930
setup() {
31+
useLegacyRoute();
3032
const pageData = usePageData();
3133
const router = useRouter();
3234

src/.vuepress/components/Sidevar.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,20 @@ watch(
6464
}
6565
.switch-list {
6666
display: flex;
67-
width: 100px;
67+
text-align: center;
68+
width: 120px;
6869
margin-right: 12px;
6970
border-radius: 14px;
7071
background-color: #f0f1fa;
7172
list-style-type: none;
7273
padding: 4px;
7374
margin: 0;
75+
margin-left: 16px;
7476
margin-top: 1rem;
7577
7678
.switch-type {
7779
padding: 3px 9px;
80+
flex: 1;
7881
cursor: pointer;
7982
border-radius: 14px;
8083
background-color: transparent;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { onMounted } from 'vue';
2+
import { useRoute, withBase } from 'vuepress/client';
3+
import { getDocVersion } from '../utils/index.js';
4+
5+
const useLegacyRoute = () => {
6+
const route = useRoute();
7+
onMounted(() => {
8+
let lang = 'zh';
9+
const allPath: string[] = route.path?.split('/');
10+
if (allPath && allPath.length > 2) {
11+
if ((allPath[0]==='' && allPath[1] === 'zh')||(allPath[0]==='zh')) {
12+
lang = 'zh';
13+
} else {
14+
lang = '';
15+
}
16+
}
17+
const version = getDocVersion(route.path, '');
18+
// 如果路径中包含 Tree 或 Table,并且当前页面内容为 404,则跳转到对应的 Quick Start 页面
19+
if (version==='latest' || version.includes('-Tree') || version.includes('-Table')) {
20+
if(document.getElementsByClassName('not-found-hint').length>0){
21+
// 替换 URL 中的 Tree 或 Table 之后的内容为 QuickStart/QuickStart.html
22+
23+
window.location.href = `${window.location.origin}${withBase(lang+'/UserGuide/'+version+'/QuickStart/QuickStart.html')}`;
24+
//window.location.href = `${window.location.origin}/docs/zh/UserGuide/V2.0.1/${dialect}/QuickStart/QuickStart.html`;
25+
}
26+
}
27+
});
28+
}
29+
30+
export default useLegacyRoute;
31+
export { useLegacyRoute };

0 commit comments

Comments
 (0)