diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 7c27f6e..acb9a63 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -24,18 +24,25 @@ module.exports = { }, plugins: ['vue', 'prettier', '@typescript-eslint'], // 显式注册所有插件 rules: { - 'vue/no-undef-components': 'error', + // 允许使用 router-link 和 router-view 组件 + 'vue/no-undef-components': [ + 'error', + { + ignorePatterns: ['router-link', 'router-view'] + } + ], // 针对非 Vue 文件禁用 Vue 规则 // 'vue/no-unregistered-components': [ // 'error', // { ignorePatterns: ['^router$', '^store$'] } // 可选:忽略特定组件名称 // ], - 'vue/multi-word-component-names': [ - 'error', - { - ignores: ['Test'] // 可选:忽略特定组件名 - } - ], + 'vue/multi-word-component-names': 'off', + // 'vue/multi-word-component-names': [ + // 'error', + // { + // ignores: ['Test'] // 可选:忽略特定组件名 + // } + // ], // 其他自定义规则 'prettier/prettier': 'error', diff --git a/src/App.vue b/src/App.vue index 87c6450..4a48484 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,33 +1,42 @@ - - - diff --git a/src/main.ts b/src/main.ts index 4a2541f..f73434a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,18 @@ -import { createApp } from 'vue' -import './style.css' +// src/main.ts +import { ViteSSG } from 'vite-ssg' +import { createWebHistory } from 'vue-router' import App from './App.vue' -import './styles/reset.css' // 引入重置样式 +import routes from './router/routes' +import './style.css' -createApp(App).mount('#app') +export const createApp = ViteSSG( + App, + { + history: createWebHistory(), + routes + }, + ctx => { + // 确保路由插件被安装 + ctx.app.use(ctx.router) // 关键修改点 + } +) diff --git a/src/router/index.ts b/src/router/index.ts new file mode 100644 index 0000000..a1ce10b --- /dev/null +++ b/src/router/index.ts @@ -0,0 +1,20 @@ +// src/router/index.ts +import { createRouter, createWebHistory } from 'vue-router' +import routes from './routes' + +const router = createRouter({ + history: createWebHistory(), + routes, + scrollBehavior(_to, _from, savedPosition) { + // 添加下划线标记未使用参数 + return savedPosition || { top: 0 } + } +}) + +router.beforeEach((_to, _from, next) => { + // 添加下划线 + // document.title = to.meta.title || '极简官网' // 确保meta.title类型正确 + next() +}) + +export default router diff --git a/src/router/routes.ts b/src/router/routes.ts new file mode 100644 index 0000000..3496a35 --- /dev/null +++ b/src/router/routes.ts @@ -0,0 +1,31 @@ +// src/router/routes.ts +import type { RouteRecordRaw } from 'vue-router' // 添加type关键字 +import Home from '@/views/Home.vue' +import About from '@/views/About.vue' + +const routes: RouteRecordRaw[] = [ + { + path: '/', + name: 'Home', + component: Home, + meta: { + title: '首页 - 极简官网' // 明确指定title为string类型 + } as { title: string } // 强制类型断言 + }, + { + path: '/about', + name: 'About', + component: About, + meta: { + title: '关于我们 - 极简官网' + } as { title: string } + }, + { + path: '/:pathMatch(.*)*', + name: 'NotFound', + component: () => import('@/views/NotFound.vue'), + meta: { title: '404 - 页面不存在' } as { title: string } + } +] + +export default routes diff --git a/src/views/About.vue b/src/views/About.vue new file mode 100644 index 0000000..8080add --- /dev/null +++ b/src/views/About.vue @@ -0,0 +1,18 @@ + + + + + diff --git a/src/views/Contact.vue b/src/views/Contact.vue new file mode 100644 index 0000000..15f3cfa --- /dev/null +++ b/src/views/Contact.vue @@ -0,0 +1,7 @@ + + diff --git a/src/views/Home.vue b/src/views/Home.vue new file mode 100644 index 0000000..8ec1fad --- /dev/null +++ b/src/views/Home.vue @@ -0,0 +1,18 @@ + + + + + diff --git a/src/views/NotFound.vue b/src/views/NotFound.vue new file mode 100644 index 0000000..74053fb --- /dev/null +++ b/src/views/NotFound.vue @@ -0,0 +1,9 @@ + + + + diff --git a/tsconfig.node.json b/tsconfig.node.json index 5eee59c..6e68380 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -6,9 +6,10 @@ "ES2022", "DOM", ], + "baseUrl": "./", "paths": { "@/*": [ - "./src/*" + "src/*" ] // 添加路径别名 },