免费套餐默认内置的404页面是这样的

虽然挺简洁明了,但是对用户没有帮助。特别是像Hexo之类的可以同主题一起渲染成更好康的404页面。

下面通过修改now.json配置和api routes实现使用自定义404页面。

特别一说 这功能咕了快有一年多了( https://spectrum.chat/zeit/now/custom-404-page~1f921045-60d9-477b-b23c-1626c9fa1565


Now v2 now.json

https://zeit.co/docs/configuration#routes/advanced/custom-404

Now2项目中,Vercel(ZEIT)采用根目录下的now.json文件配置来自定义其构建过程,可通过Routes进行重定向,指定页面,自定义404等功能。

对于filesystem中不匹配的 返回处于根目录的 404.html 404错误页面文件

1
2
3
4
5
6
7
{
  "version": 2,
  "routes": [
    { "handle": "filesystem" },
    { "src": "/(.*)", "status": 404, "dest": "/404.html" }
  ]
}

hexo添加方式: 如果你采用的是Vercel(ZEIT) Page的话,只需在Hexo目录下的 /source 新建 now.json 并复制上述代码,hexo g 即可生成在 /public。 如果是托管代码自动部署的,则添加 now.json 在根目录即可。

注:使用gulp压缩的最好忽略此文件,以避免出现奇怪的现象。

实在懒得复制的直接下载我的配置也行。

顺便也可以康下我的404页面

Zero Config

以下是官方屁话

With Now 2.0, we introduced the most powerful and scalable platform for static websites and serverless functions powered by any language or framework This came at the expense of writing now.json files. Today, we are introducing Zero Config, a conventional and completely backwards-compatible approach to deployment. https://zeit.co/blog/zero-config

是的,官方又咕了 https://spectrum.chat/zeit/now/custom-404-page~1f921045-60d9-477b-b23c-1626c9fa1565?m=MTU4MDQyNzQ3OTI1Ng==