繁体   English   中英

我想使用 html 文件作为我在 next.js 上的主页

[英]I want to use an html file as my homepage on next.js

当有人访问我的根目录“https://example.com/”时,我想呈现一个 normal.html 文件。 (index.html) 我怎样才能用 next.js 做到这一点?

我做了一个研究并像这样编辑我的配置文件,

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  rewrites: async () => {
    return [
      {
        source: "/public/myfile.html",
        destination: "/pages/api/myfile.js",
      },
    ];
  },
};

/pages/api/myFile.js

import fs from "fs";
const filename = "/index.html";

export default async function api(req, res) {
  res.setHeader("Content-Type", "text/html; charset=utf-8");
  res.write(await fs.readFileSync(filename, "utf-8"));
  res.end();
}

module.exports = nextConfig;

但是当我点击这个 url 时,这个配置文件呈现 my.html 页面: https://example.com/index.html

  rewrites: async () => [
    {
      source: "/",
      destination: "/index.html",
    },
  ],

在我的 next.config.js 文件中添加了这个(在 nextConfig 对象中)

我的 /public 目录中有一个 index.html 文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM