【发布时间】:2020-01-23 17:03:03
【问题描述】:
我已经使用 Netlify 部署了我的网站,但我遇到了路由问题。
这是我的网站:https://redux-co.netlify.com/
还有我的 GitHub 存储库:https://github.com/jenna-m/redux-co
具体来说,如果用户导航到主页以外的任何页面并刷新页面,则默认 Netlify 404 呈现。从 404 页面,如果我导航回主页并刷新,则呈现主页。
另外,我的自定义 404 页面无法像使用 localhost:3000 时那样工作,但我希望在处理我的自定义 404 组件之前先解决这个刷新问题。
我正在使用 React 和 react-router,并且我知道由于我使用的是 react-router,我的网站不会立即部署。
这是我的_redirects 文件,它与我的index.html 文件位于/public 文件夹中:
/* /index.html 200
这是我的“build”,位于package.json:
…
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && cp build/index.html build/404.html",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
…
我读到过其他人遇到这种情况以及他们为克服这个问题所做的工作。这是我到目前为止所引用的……
https://www.freecodecamp.org/news/how-to-deploy-a-react-application-to-netlify-363b8a98a985/
https://hugogiraudel.com/2017/05/13/using-create-react-app-on-netlify/
这个人使用的是 Vue 而不是 React,但我还是尝试了这些解决方案:
https://github.com/vuejs/vuepress/issues/457#issuecomment-390206649
https://github.com/vuejs/vuepress/issues/457#issuecomment-463745656
【问题讨论】:
-
嗯,奇怪。也许您在 Netlify 设置中设置了错误
标签: reactjs react-router http-status-code-404 netlify