使用 create-react-app 部署 github 页面的 React-router 问题 [英] React-router issues with deploying github pages, with create-react-app

查看:47
本文介绍了使用 create-react-app 部署 github 页面的 React-router 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将一个简单的 React 应用程序部署到 github 页面时遇到了最困难的时期.您将一个文件移动到错误的目录,它会导致整个过程中断.

I am having the hardest time deploying a simple react application to github pages. You move one file to a wrong directory and it throws the entire process off.

运行 npm run build 后该怎么办?

What do I do once I run npm run build?

这会将我的所有文件放入构建文件夹,但浏览器仍然不断给我 404 错误,认为在初始 url 路由的/"之后键入的任何内容都在寻找来自服务器的实际文件.我只想使用/之后的任何内容作为我在 React Router 中设置的路由... :(

That puts all my files into a build folder, but the browser still keeps giving me 404 errors, thinking that anything typed after the initial url route's "/" is looking for an actual file from a server. I just want to use whatever comes after the / as routes that I set up in my React Router... :(

推荐答案

Create-React-App 有一份关于如何将您的构建部署到 Github Pages 和 Heroku 的详细文档.您可以在此处阅读."客户端注意事项-side 路由" 部分.

Create-React-App has a detailed documentation on how to deploy your build to Github Pages and Heroku. You can read it here. Your specific issue is covered in "Notes on client-side routing" section.

这篇关于使用 create-react-app 部署 github 页面的 React-router 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆