Skip to content

Commit

Permalink
fix: fix relative navigation (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dj-Denis authored Sep 14, 2023
1 parent 5336360 commit 475e357
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function History({ onChange }) {
export function Link({ to, onClick, children, ...props }) {
const handleClick = (event) => {
event.preventDefault();
window.history.pushState({}, to, window.location.origin + to);
window.history.pushState({}, to, new URL(to, window.location));
onClick({
pathname: window.location.pathname,
search: window.location.search,
Expand Down
40 changes: 40 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,43 @@ def sample():

await display.page.go_back()
await display.page.wait_for_selector("#root")


async def test_relative_links(display: DisplayFixture):
@component
def sample():
return simple.router(
route("/", link("Root", to="/a", id="root")),
route("/a", link("A", to="/a/b", id="a")),
route("/a/b", link("B", to="../a/b/c", id="b")),
route("/a/b/c", link("C", to="../d", id="c")),
route("/a/d", link("D", to="e", id="d")),
route("/a/e", link("E", to="../default", id="e")),
route("*", html.h1({"id": "default"}, "Default")),
)

await display.show(sample)

for link_selector in ["#root", "#a", "#b", "#c", "#d", "#e"]:
lnk = await display.page.wait_for_selector(link_selector)
await lnk.click()

await display.page.wait_for_selector("#default")

await display.page.go_back()
await display.page.wait_for_selector("#e")

await display.page.go_back()
await display.page.wait_for_selector("#d")

await display.page.go_back()
await display.page.wait_for_selector("#c")

await display.page.go_back()
await display.page.wait_for_selector("#b")

await display.page.go_back()
await display.page.wait_for_selector("#a")

await display.page.go_back()
await display.page.wait_for_selector("#root")

0 comments on commit 475e357

Please sign in to comment.