visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

Router does not match absolute URLs correctly #559

Open openjck opened 4 years ago

openjck commented 4 years ago

Steps to reproduce

  1. Save the following code to a file named index.html in a local directory
  2. Run npx serve /path/to/that/directory
  3. Visit http://localhost:5000
  4. Click the second button, which calls page.show("http://localhost:5000/")

Expected result

Active page: Home

Actual result

Active page: Not found

Code

<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8" />
    <title>page.js bug demo</title>
  </head>
  <body>
    <button id="relative">Navigate to /</button>
    <button id="absolute">Navigate to http://localhost:5000/</button>
    <p>Active page: <span id="active-page"></span></p>

    <script src="https://unpkg.com/page@1.11.5/page.js"></script>
    <script>
      page.configure({ window: window });

      function showPage(name) {
        document.querySelector("#active-page").innerText = name;
      }

      page("/", () => showPage("Home"));
      page("*", () => showPage("Not found"));
      page.start();

      document.querySelector("#relative").addEventListener("click", () => {
        page.show("/"); // Active page: Home
      });

      document.querySelector("#absolute").addEventListener("click", () => {
        page.show("http://localhost:5000/"); // Active page: Not found
      });
    </script>
  </body>
</html>

Other notes