Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 为什么react路由器在服务器中不工作?刷新页面后显示404错误_Reactjs_Server_React Router - Fatal编程技术网

Reactjs 为什么react路由器在服务器中不工作?刷新页面后显示404错误

Reactjs 为什么react路由器在服务器中不工作?刷新页面后显示404错误,reactjs,server,react-router,Reactjs,Server,React Router,我有一个部署在服务器上的项目,但是react路由器不能正常工作。但是,它在本地服务器中运行良好。我不知道为什么?我的意思是,当我转到不同的页面并刷新时,它会显示404错误。请,有人来帮忙!!!例如: 我的路由器代码 const App=(props)=>{ return( <Router history={browserHistory}> <Route path={"/"} component={Root}>

我有一个部署在服务器上的项目,但是react路由器不能正常工作。但是,它在本地服务器中运行良好。我不知道为什么?我的意思是,当我转到不同的页面并刷新时,它会显示404错误。请,有人来帮忙!!!例如:

我的路由器代码

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>
    )
  };
const-App=(道具)=>{
返回(
//使默认页面显示在主页面中
//传递参数
//传递参数
//传递参数
//传递参数
//传递参数
//传递参数
//传递参数
//传递参数
//传递参数
)
};

代码中的浏览器历史记录可能需要一个基本名称。查看类似问题的答案是否适用于您:

您需要将basename添加到userstory中

const browserHistory = useRouterHistory(createHistory)({
     basename: '/myPage/public'
    });
//中间件

const middleware = [
  ...
  ...
 routerMiddleware(browserHistory) 
];
//为Redux应用所有中间件

const enhancers = composeEnhancers(
  applyMiddleware(...middleware)
);