create-react-app の仕様
create-react-app のビルドでは、package.jsonのhomepageの値を参照しています。
無指定だとルートパスは/とります。package.json に"homepage": "https://example.com/customと設定するとルートパスは/customになります。
Static Server での起動
create-react-app で Static Server の起動にはserveが推奨されています。serveはルートパスが必ず/になり、カスタムできません。
ルートパスを変更した場合は、expressなどの Web フレームワークを使って、自作する必要があります。expressを利用した例は以下のとおりです。
const express = require("express");
const path = require("path");
const app = express();
app.use("/custom", express.static(path.join(__dirname, "build")));
app.get("/custom", function (req, res) {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
app.listen(9000);これでhttp://localhost:9000/customからアクセスできるようになります。