_redirects
/* /index.html 200!
的package.json
"scripts" : {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
如果你要将_redirects
放入你的create react app
,它应该进入public
文件夹。构建文件夹不应该在Netlify等连续构建解决方案的存储库中。
你在这里建议的_redirects
通常用于当你使用像路由器这样的路由器这样的单页应用程序时,并且想要一条路径,当它不存在时总是去index.html
。您不希望它解析资产价值路径。
无论浏览器请求什么网址,此重定向规则都将为index.html提供服务,而不是提供404。
_redirects
/* /index.html 200
如果您强制index.html页面提供服务,即使没有有效路径(您的资产正在发生这种情况),也会发生什么。
_redirects
移动到public
文件夹!
,所以如果找到路径它正确地服务它并不总是强制它到index.html