最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to omit the index.html in a react app? - Stack Overflow

programmeradmin3浏览0评论

I have a next.js react app that is serving several static projects in the public folder:

public/
  ├── project1/
  |   ├── index.html
  |   ├── script.js
  |   └── ...
  ├── project2/
  |   ├── index.html
  |   ├── script.js
  |   └── ...
  └── ...

However, going to localhost:3000/project1 results in a 404 page, and I have to go to localhost:3000/project1/index.html for it to work.

How can I omit the index.html, so going to localhost:3000/project1 works?

I tried doing this in my next.config.ts:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  async rewrites() {
    return [
      {
        source: "/project1",
        destination: "/project1/index.html",
      },
    ];
  },
};

export default nextConfig;

Now I can see the page in localhost:3000/project1, but it can no longer read the js and all other assets because it read from localhost:3000/script.js instead of localhost:3000/project1/script.js.

Most of these projects are quite big so I cannot manually change the relative path of everything in there.

发布评论

评论列表(0)

  1. 暂无评论