我有在服务器中部署的项目,但反应路由器不能正常工作。但是,它在本地服务器中工作正常。我不知道为什么?我的意思是,当我去不同的页面并刷新时,它显示我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>
)
};
答案 0 :(得分:1)
代码中的browserHistory可能需要一个基本名称。看看类似问题的答案是否适合您:https://stackoverflow.com/a/36765496/4772334
答案 1 :(得分:0)
您需要使用useRouterHistory添加basename。
const browserHistory = useRouterHistory(createHistory)({
basename: '/myPage/public'
});
//中间件
const middleware = [
...
...
routerMiddleware(browserHistory)
];
//为Redux应用所有中间件
const enhancers = composeEnhancers(
applyMiddleware(...middleware)
);