From: qixiao <34623348+qixiaobro@users.noreply.github.com> Date: Wed, 20 Apr 2022 14:01:29 +0000 (+0800) Subject: docs: add history mode vercel example (#1370) X-Git-Tag: v4.0.15~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e560f30846d82cc7abc48ae3fe6fdc61a866a534;p=thirdparty%2Fvuejs%2Frouter.git docs: add history mode vercel example (#1370) --- diff --git a/docs/guide/essentials/history-mode.md b/docs/guide/essentials/history-mode.md index 1ccd4559..d0e95a67 100644 --- a/docs/guide/essentials/history-mode.md +++ b/docs/guide/essentials/history-mode.md @@ -172,6 +172,16 @@ In vue-cli, nuxt, and vite projects, this file usually goes under a folder named You can more about the syntax on [Netlify documentation](https://docs.netlify.com/routing/redirects/rewrites-proxies/#history-pushstate-and-single-page-apps). You can also [create a `netlify.toml`](https://docs.netlify.com/configure-builds/file-based-configuration/) to combine _redirections_ with other Netlify features. +### Vercel + +Create a `vercel.json` file under the root directory of your project with the following: + +```json +{ + "rewrites": [{ "source": "/:path*", "destination": "/index.html" }] +} +``` + ## Caveat There is a caveat to this: Your server will no longer report 404 errors as all not-found paths now serve up your `index.html` file. To get around the issue, you should implement a catch-all route within your Vue app to show a 404 page: diff --git a/docs/zh/guide/essentials/history-mode.md b/docs/zh/guide/essentials/history-mode.md index 1f9d5139..98a7bd19 100644 --- a/docs/zh/guide/essentials/history-mode.md +++ b/docs/zh/guide/essentials/history-mode.md @@ -167,6 +167,16 @@ rewrite { 你可以在 [Netlify 文档](https://docs.netlify.com/routing/redirects/rewrites-proxies/#history-pushstate-and-single-page-apps)中找到更多关于语法的信息。你也可以[创建一个 `netlify.toml`](https://docs.netlify.com/configure-builds/file-based-configuration/) 来结合其他 Netlify 功能的重定向。 +### Vercel + +在项目根目录创建一个`vercel.json`文件,内容如下: + +```json +{ + "rewrites": [{ "source": "/:path*", "destination": "/index.html" }] +} +``` + ## Caveat 这有一个注意事项。你的服务器将不再报告 404 错误,因为现在所有未找到的路径都会显示你的 `index.html` 文件。为了解决这个问题,你应该在你的 Vue 应用程序中实现一个万能的路由来显示 404 页面。