Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router does not match absolute URLs correctly #559

Open
openjck opened this issue Mar 26, 2020 · 0 comments
Open

Router does not match absolute URLs correctly #559

openjck opened this issue Mar 26, 2020 · 0 comments

Comments

@openjck
Copy link

openjck commented Mar 26, 2020

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/[email protected]/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

  • The same thing happens when page.redirect is used
  • By comparison, pushState and replaceState accept absolute URLs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant