Skip to content

Commit

Permalink
Merge branch 'main' into ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
YDX-2147483647 authored Oct 18, 2024
2 parents 2601fda + 09c6878 commit 03811dd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,18 @@ const router = createRouter({
},
});

router.beforeEach(({ path }) => {
// 此处只是尽快响应,设置大类标题。
// 之后各组件可以再覆盖。
router.beforeEach((to) => {
// 兼容旧hash模式的链接
// 例:/#/paper/show/15 👉 /paper/15
if (to.path === '/' && to.hash.startsWith('#/')) {
let path = to.hash.slice('#'.length)
path = path.replace(/^\/(paper|course)\/show\//, '/$1/')
return path
}


// 设置大类标题
// 此处只是尽快响应,之后各组件可以再覆盖。

const titleMap: Record<string, string> = {
home: '主页',
Expand All @@ -157,7 +166,7 @@ router.beforeEach(({ path }) => {
gallery: '话廊',
report: '举报',
}
const top = path.split('/').filter(piece => piece.length > 0)[0] ?? ''
const top = to.path.split('/').filter(piece => piece.length > 0)[0] ?? ''
const title = titleMap[top] ?? top
if (title) setTitle(title)
})
Expand Down

0 comments on commit 03811dd

Please sign in to comment.