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 未找到页面不';我不能在服务器上工作_Reactjs_React Router - Fatal编程技术网

Reactjs 未找到页面不';我不能在服务器上工作

Reactjs 未找到页面不';我不能在服务器上工作,reactjs,react-router,Reactjs,React Router,首先,我的应用程序在localhost上运行良好。除了NotFound(404)页面之外,每个组件和URL都在服务器上工作 我遗漏了什么?也许这个答案会很有帮助:不,它根本不起作用。如果你想捕获所有的路由,你不需要指定路径。你能试试看吗?此外,如果不为组件提供任何道具,则无需使用渲染。在这些情况下,请使用组件={}。@RoyScheffers你是什么意思?我只想捕捉应用程序中没有的路线。此外,我还尝试了。没什么变化。很抱歉不清楚。我指的是任何其他未指定的路线。如果未指定路径,则如果上述路径不匹配

首先,我的应用程序在localhost上运行良好。除了NotFound(404)页面之外,每个组件和URL都在服务器上工作


我遗漏了什么?

也许这个答案会很有帮助:不,它根本不起作用。如果你想捕获所有的路由,你不需要指定路径。你能试试看吗?此外,如果不为组件提供任何道具,则无需使用渲染。在这些情况下,请使用
组件={}
。@RoyScheffers你是什么意思?我只想捕捉应用程序中没有的路线。此外,我还尝试了
。没什么变化。很抱歉不清楚。我指的是任何其他未指定的路线。如果未指定
路径
,则如果上述路径不匹配,则始终渲染该路由。您还可以共享package.json和webpack.config.js吗?也许其中有一些东西可以给我们一个线索,说明为什么NotFound路由在服务器上不起作用?您使用的是什么类型的服务器?
<Switch>

        <Route
          exact
          path={'/'}
          render={() => (
          {/*something here*/}
       )} />

       <Route
        exact
        path={'/secondPage'}
        render={() => (
        {/*something here*/}
      )} />

        <Route 
         path={'*'} 
         render={() => (
         <NotFound />
      )} />

 </Switch>
ReactDOM.render(
    <BrowserRouter basename={process.env.PUBLIC_URL}><App /></BrowserRouter>, 
    document.getElementById('root')
)
{
  "homepage": "https://mywebsite.com/react-app/",

  "dependencies": {
    "escape-string-regexp": "^1.0.5",
    "lodash": "^4.17.10",
    "prop-types": "^15.6.1",
    "react": "^16.3.2",
    "react-dom": "^16.3.2",
    "react-router-dom": "^4.3.1",
    "sort-by": "^1.2.0"
  },
  "devDependencies": {
    "gh-pages": "^1.2.0",
    "react-scripts": "1.1.4"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}