refactor: 重构导航组件使用动态TDK数据和路由
This commit is contained in:
19
middleware/tdk.global.ts
Normal file
19
middleware/tdk.global.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { getTDKList } from '~/api/home/index'
|
||||
// middleware/tdk.global.ts
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
const { data: tdkData } = await getTDKList()
|
||||
// 获取当前路由
|
||||
const currentPath = to.path;
|
||||
// 根据当前路由获取对应的TDK数据
|
||||
const currentTdk = tdkData.find((item) => item.path === currentPath)
|
||||
|
||||
if (currentTdk) {
|
||||
useHead({
|
||||
title: currentTdk.title,
|
||||
meta: [
|
||||
{ name: 'description', content: currentTdk.describeText },
|
||||
{ name: 'keywords', content: currentTdk.keyword }
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user