Javascript React Router V4嵌套路由器无法重新加载页面

Javascript React Router V4嵌套路由器无法重新加载页面,javascript,reactjs,routing,react-router-dom,Javascript,Reactjs,Routing,React Router Dom,我用react创建了一个新网站,并使用react rotuter dom添加了路由 import {BrowserRouter as Router, Route, Switch} from "react-router-dom"; 并将路由器添加为:- <Switch> <Route exact path="/" component={Home}></Route> <Route path="/galery" component={Galery}&

我用react创建了一个新网站,并使用react rotuter dom添加了路由

import {BrowserRouter as Router, Route, Switch} from "react-router-dom";
并将路由器添加为:-

<Switch>
  <Route exact path="/" component={Home}></Route>
  <Route path="/galery" component={Galery}></Route>
</Switch>

对于多种图表类型的嵌套布线,我已在Gallery组件中添加了这些布线

<Route exact path={this.props.match.path} component={LineChart}></Route>
<Route path={`${this.props.match.path}/line`} component={LineChart}></Route>
<Route path={`${this.props.match.path}/lineChartFill`} component={LineChartFill}></Route>
<Route path={`${this.props.match.path}/lineChartComparision`} component={LineChartComparision}></Route>
<Route path={`${this.props.match.path}/lineChartComparisionFill`} component={LineChartComparisionFill}></Route>

路由器在点击链接时工作正常,但当我尝试重新加载页面时,页面不会再次加载

在Gallery页面中存在多个嵌套路由,当我单击这些路由时,它们会正确加载,但当我重新加载页面时,它不会加载。
请帮助我解决此问题。

服务器不知道您的客户端路由。构建过程可能会生成一个引用资源的index.html。该index.html位于
/galery/index.html
。单击“刷新”时,服务器会在
/galery/line/index.html
中查找未找到的文件


这是一个常见的问题。为了解决这个问题,许多人告诉服务器使用某种规则来提供
/galery/index.html
。这取决于文件的宿主方式。react应用程序将启动客户端,查看稍有不同的路由,并正确呈现路由。

最后,在漫游了这么多网站后,我知道react有两种类型的路由器:-

  • HashRouter用于静态路由网站,也可以称为自驱动路由

  • 用于服务器支持的路由的BrowserRouter

  • 我在我的网站上使用了错误的浏览器路由器,因为我没有任何类型的服务器支持(节点、python等) 所以我必须使用HashRouter

    import {HashRouter as Router, Route, Switch} from "react-router-dom";
    

    修复了使用Hashrouter的问题。

    谢谢@Leland Barton,我只有一个index.html,从那里我尝试加载bundle.js,但当我加载页面时,它再次在/galey/index.html中搜索index.html,但我没有名为/galey的那种文件夹,所以我不知道如何解决这个问题。使用路由器有什么诀窍吗?这是你如何主持react应用程序的问题。您需要查找服务器,了解如何重定向到该文件。