【问题标题】:ReactJS Not Found The requested URL /AboutMe was not found on this server未找到 ReactJS 在此服务器上未找到请求的 URL /AboutMe
【发布时间】:2020-01-23 08:43:13
【问题描述】:

我创建了一个没有服务器的 react 应用程序(也使用 react-router)并构建了它。 将其上传到主机后,它工作正常,直到我尝试将 url 写入地址栏, 它显示“Not Found The requested URL /AboutMe was not found on this server.”

每次我尝试将它写入地址栏时,我是否还需要创建一个服务器来捕获 url (/AboutMe)?

<Router history={history}>  
                <React.Fragment>
                    <Switch>
                        <Route exact path = "/" render = {() => (<Home value = {info} />)} />
                        <Route exact path = "/AboutMe" render = {() => (<AboutMe value = {info} />)}/>
                        <Route component = {NotFound} />
                    </Switch>
                </React.Fragment>

【问题讨论】:

  • 你能告诉我们你的路线代码吗?
  • 当然,我会编辑我的问题
  • 使用哈希路由器的快速解决方案

标签: reactjs web react-router react-router-v4 react-router-dom


【解决方案1】:

您需要在 SPA 模式下配置您的网络服务器(将所有请求重定向到 /index.html)。 nginx配置示例

root /var/www/your_site;

location / {
    try_files $uri /index.html;
}

【讨论】:

    【解决方案2】:

    快速解决方案: 像这样使用哈希路由器: import { HashRouter as Router, Route, Switch, Link } from 'react-router-dom';

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-28
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多