Router does not match absolute URLs correctly
openjck opened this issue · comments
Steps to reproduce
- Save the following code to a file named index.html in a local directory
- Run
npx serve /path/to/that/directory
- Visit http://localhost:5000
- 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
- The same thing happens when
page.redirect
is used - By comparison, pushState and replaceState accept absolute URLs