Skip to content

Commit

Permalink
feat: 支持页面级 meta 标题
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Jul 29, 2023
1 parent a53b4f2 commit 8bb19fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pages/[...notFound].vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const typedRef = useTyped([' is not found!'])
<route lang="json">
{
"meta": {
"title": "404",
"layout": "notFound"
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { setupLayouts, createGetRoutes } from 'virtual:meta-layouts'
import { createRouter, createWebHistory } from 'vue-router'
import { routes as fileRoutes } from 'vue-router/auto/routes'

declare module 'vue-router' {
// 在这里定义你的 meta 类型
// eslint-disable-next-line no-unused-vars
interface RouteMeta {
title?: string
layout?: string
}
}

export const router = createRouter({
history: createWebHistory(),
routes: setupLayouts(fileRoutes),
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { router } from './router'

useTitle(
() => {
const { path } = router.currentRoute.value
const { path, meta } = router.currentRoute.value
if (meta.title) {
return ${meta.title}`
}
if (path === '/') {
return '· home'
}
Expand Down

0 comments on commit 8bb19fc

Please sign in to comment.