【问题标题】:ReactJS - Location ... did not match any specific any routesReactJS - 位置......不匹配任何特定的任何路线
【发布时间】:2017-07-22 16:42:11
【问题描述】:

我使用 webpack 来打包我的所有文件。 我在带有 index.html 的目录中有一个 bundle.js 文件

当我在浏览器中打开它时,它给了我一个错误:-

Warning: [react-router] Location "/home/vivek/Desktop/prismo-front/build/index.html" did not match any routes

我的文件目录如下所示:-

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, 
   shrink-to-fit=no">
  <meta name="theme-color" content="#000000">
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js">
  </script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
  <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
  <title>Prismo</title>
  </head>
  <body>
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <div id="root">ds</div>
    <script type="text/javascript" src="bundle.js" charset="utf-8">
  </script>

  </body>
</html>

【问题讨论】:

    标签: reactjs webpack react-router


    【解决方案1】:

    运行以下命令以在本地提供您的文件。

    1. 安装:npm install -g http-server。
    2. cd 进入build
    3. 运行http-server
    4. 在浏览器中转到http://localhost:8080/

    或将您的文件上传到服务器,您将不会遇到此问题。你不能在本地运行你的 index.html 文件,因为它不能很好地与用于 React Router 的 History 配合使用。

    【讨论】:

    • 如何运行 http-server ?我收到此错误:- No command 'run' found: 当我这样做时:- run http-server
    • 你不输入 run 只是 http-server
    • 谢谢!关于为什么我们不能在本地文件上使用历史的更多信息。 http-server 的“历史”如何?我也可以在普通的 xampp 服务器上运行它吗?
    • 因为它试图匹配 React-Router 中的“/home/vivek/Desktop/prismo-front/build/index.html”。如果您在本地加载,则“/”在此上下文中不存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多