{ "name": "sample-react", + "homepage": "/app", "version": "0.1.0", "private": true, "dependencies": { ... } } これで、ビルド時にすべてのアセットのパス(favicon.icoやmanifest.jsonなど)がindex.html上で相対的に読み込まれるようになる ルーティングの設定 サイトのベースパスを考慮したルーティングを設定するには、React Router v6が提供する<BrowserRouter>コンポーネントのbasename要素を次のように設定する import { BrowserRouter, Routes, Route } from 'react-router-dom' function App() { return ( - <BrowserRouter> +
![Reactで初期のサイトパスを変更する方法](https://cdn-ak-scissors.b.st-hatena.com/image/square/6435d2dac605f71333ffbe269e1fe950bacff70b/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--R82gXszq--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3AReact%2525E3%252581%2525A7%2525E5%252588%25259D%2525E6%25259C%25259F%2525E3%252581%2525AE%2525E3%252582%2525B5%2525E3%252582%2525A4%2525E3%252583%252588%2525E3%252583%252591%2525E3%252582%2525B9%2525E3%252582%252592%2525E5%2525A4%252589%2525E6%25259B%2525B4%2525E3%252581%252599%2525E3%252582%25258B%2525E6%252596%2525B9%2525E6%2525B3%252595%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_34%3A%2525E3%252581%252595%2525E3%252581%2525A3%2525E3%252581%2525A8%252Cx_220%252Cy_108%2Fbo_3px_solid_rgb%3Ad6e3ed%252Cg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyLzY0ZmQ2ZmJhZjQuanBlZw%3D%3D%252Cr_20%252Cw_90%252Cx_92%252Cy_102%2Fco_rgb%3A6e7b85%252Cg_south_west%252Cl_text%3Anotosansjp-medium.otf_30%3A%2525E6%2525A0%2525AA%2525E5%2525BC%25258F%2525E4%2525BC%25259A%2525E7%2525A4%2525BEZOZO%252Cx_220%252Cy_160%2Fbo_4px_solid_white%252Cg_south_west%252Ch_50%252Cl_fetch%3AaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyLzc5NzA4ZGUwNTUuanBlZw%3D%3D%252Cr_max%252Cw_50%252Cx_139%252Cy_84%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)