我一直在尝试将我的 React Web 应用程序提升到 gh 页面上一段时间,但它不会中断并且加载为空白。链接在这里:https://00eemsy.github.io/my-cv-website/
我已经按照其他 Stack Overflow 帖子上的建议尝试了很多方法,但没有一个有效:
package.json
的"private": true
更改为"private": false
homepage
URL ("homepage": "https://00eemsy.github.io/my-cv-website"
)BrowserRouter
实施到我的 index.js
文件中const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<BrowserRouter basename={process.env.PUBLIC_URL}>
{/* <App/> */}
<nav>
<Link to='/'></Link>
</nav>
<Routes>
<Route exact path='/' element={<App />}/>
</Routes>
</BrowserRouter>
);
在
localhost
、npm run build
和 gh-pages -d build
上一切看起来都很好,但我仍然在任何其他设备或除 Chrome(我最常用的浏览器)之外的任何其他网络浏览器上看到空白网页。很确定没有错误的链接,但似乎它只在 Chrome 上显示正常,而在其他地方却显示不出来。
这个方法对我有用:https://dev.to/rashidshamloo/deploying-vite-react-app-to-github-pages-35hf
不要忘记将发布源设置为Github中的
gh-pages
分支Settings > Pages > Build and Deployment