[英]Advanced Routing in Netlify React
I had problems with the routing after deploying my react app on netlify.在 netlify 上部署我的 React 应用程序后,我遇到了路由问题。 I inserted a _redirects file to my public folder with this code
/* /index.html 200
as recommended.我按照建议使用此代码
/* /index.html 200
将 _redirects 文件插入到我的公共文件夹中。
Yet, when I refresh the page from an advanced route eg '/sceneries/beach', it always pushes me back to the index page.然而,当我从高级路线(例如“/sceneries/beach”)刷新页面时,它总是将我推回到索引页面。 Locally it has been working perfectly before.
在本地,它之前一直运行良好。 Do you know how to solve this?
你知道如何解决这个问题吗? My routes currently look like this:
我的路线目前是这样的:
in index.js在 index.js 中
ReactDOM.render((
<Router history={history}>
<App />
</Router>
), document.getElementById('root'));
in App.js在 App.js 中
<BrowserRouter>
<Route path='/' component ={Home} />
<Route path='/sceneries/:id' component ={Comparison} />
<Redirect from="*" to="/" />
</BrowserRouter>
Thanks a lot in advance!非常感谢! I really appreciate some help!
我真的很感谢一些帮助!
I had the same problem as you when I created a React app and deployed it on Netlify.当我创建一个 React 应用程序并将其部署在 Netlify 上时,我遇到了与您相同的问题。 This is what worked for me, based on this solution :
基于此解决方案,这对我有用:
netlify.toml
in the root/main folder of your project.netlify.toml
的文件。 [[redirects]] from = "/*" to = "/index.html" status = 200
Let me know if you have any additional questions, I'm happy to help :)如果您有任何其他问题,请告诉我,我很乐意为您提供帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.