Skip to content

fix: fix relative navigation #24

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

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")