为什么react

编程入门 行业动态 更新时间:2024-10-16 00:19:48
为什么react-router在服务器上不起作用?(Why react-router does not work in the server? It shows 404 error after refreshing the page)

我有在服务器中部署的项目,但反应路由器不能正常工作。 但是,它在本地服务器中工作正常。 我不知道为什么? 我的意思是,当我去不同的页面并刷新时,它显示我404错误。 请有人帮忙!!! 例如: https : //sciencepark.kz/researchpage

我的反应路由器代码

const App=(props)=>{ return( <Router history={browserHistory}> <Route path={"/"} component={Root}> <IndexRoute component={Layout}/> // make default page appears in main page <Route path={"newspage"} component={NewsPageContainer}/> //passing params <Route path={"researchpage"} component={ResearchPageContainer}/> //passing params <Route path={"servicepage"} component={ServicePage}/> //passing params <Route path={"businessincubatorpage"} component={BusinessIncubatorPage}/> //passing params <Route path={"startuppage"} component={StartUpPageContainer}/> //passing params <Route path={"fullinfomedia(/:id)"} component={FullInfoMediaContainer}/> //passing params <Route path={"fullinfonews(/:id)"} component={FullInfoNewsContainer}/> //passing params <Route path={"fullinfostartups(/:id)"} component={FullInfoStartUpsContainer}/> //passing params <Route path={"fullinforesearches(/:id)"} component={FullInfoResearchesContainer}/> //passing params <Route path={"layout"} component={Layout}/> </Route> <Route path={"layout"} component={Layout}/> </Router> ) };

I have the project that was deployed in the server, but the react router doesn`t work properly. However, it works fine in the local server. I have no idea why? I mean that when i go to different page and refresh, it shows me 404 error. Please, someone help!!! For example: https://sciencepark.kz/researchpage

my react router code

const App=(props)=>{ return( <Router history={browserHistory}> <Route path={"/"} component={Root}> <IndexRoute component={Layout}/> // make default page appears in main page <Route path={"newspage"} component={NewsPageContainer}/> //passing params <Route path={"researchpage"} component={ResearchPageContainer}/> //passing params <Route path={"servicepage"} component={ServicePage}/> //passing params <Route path={"businessincubatorpage"} component={BusinessIncubatorPage}/> //passing params <Route path={"startuppage"} component={StartUpPageContainer}/> //passing params <Route path={"fullinfomedia(/:id)"} component={FullInfoMediaContainer}/> //passing params <Route path={"fullinfonews(/:id)"} component={FullInfoNewsContainer}/> //passing params <Route path={"fullinfostartups(/:id)"} component={FullInfoStartUpsContainer}/> //passing params <Route path={"fullinforesearches(/:id)"} component={FullInfoResearchesContainer}/> //passing params <Route path={"layout"} component={Layout}/> </Route> <Route path={"layout"} component={Layout}/> </Router> ) };

最满意答案

代码中的browserHistory可能需要一个basename。 看看类似问题的答案是否适合您: https : //stackoverflow.com/a/36765496/4772334

The browserHistory in your code may need a basename. See if a similar question's answer works for you: https://stackoverflow.com/a/36765496/4772334

更多推荐

本文发布于:2023-08-07 02:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:react

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!