Skip to page content
Quasar CLI with Vite - @quasar/app-vite

SSG 404 错误页面

警告!Beta 阶段

Quasar SSG 模式目前处于 “beta” 阶段。根据社区反馈,API 在未来可能会有所变动,因此每次升级 “@quasar/app-vite” 时请留意 release notes。

默认情况下,SSG 生产构建会渲染应用的 Vue Router 未找到路由,并将其写入 dist/ssg/404.html

为使其产生预期的页面,路由器应包含一个兜底路由:

/src/router/routes 文件

{
  path: '/:catchAll(.*)*',
  component: () => import('pages/ErrorNotFound.vue')
}

配置

/quasar.config file

export default defineConfig(() => ({
  ssg: {
    // 默认:'404.html'
    error404HtmlFilename: 'not-found.html'
  }
}))

如果主机提供了自己的错误页面,或者您通过 getSsgPages() 生成自定义的 404 文件,则设置 error404HtmlFilename: false

文件名本身不会配置您的主机。Netlify、Cloudflare Pages、Vercel 和 GitHub Pages 等静态提供商会自动识别根目录下的 404.html。其他服务器可能需要显式规则。例如 nginx:

location / {
    try_files $uri $uri/ =404;
}

error_page 404 /404.html;

保持 HTTP 响应状态为 404;用 200 响应提供正确的标记会造成软 404。更多特定主机的指南请参阅 部署 SSG