我已经用Netlify部署了我的站点,但我在路由方面遇到了问题.
这是我的网站:https://redux-co.netlify.com/
我的GitHub回购协议:https://github.com/jenna-m/redux-co
具体地说,如果用户导航到主页之外的任何页面并刷新该页面,则会呈现默认的Netlify 404.从404页面,如果我导航回主页并刷新,主页将被呈现.
此外,我的自定义404页面在我localhost:3000
岁时无法正常工作,但我希望在处理自定义404组件之前先解决这个刷新问题.
我使用的是React和React路由,我知道由于我使用的是React路由,我的网站不会立即部署.
这是我的_redirects
文件,与我的index.html
文件一起放在/public
文件夹中:
/* /index.html 200
这是位于package.json
的我的“build”
:
…
"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 ,但我还是try 了以下解决方案:
https://github.com/vuejs/vuepress/issues/457#issuecomment-390206649
https://github.com/vuejs/vuepress/issues/457#issuecomment-463745656