1
1
mirror of https://github.com/srid/ema.git synced 2024-11-29 09:25:14 +03:00

Handle switching local anchors

This commit is contained in:
Sridhar Ratnakumar 2022-03-24 14:58:35 -04:00
parent 74557c90ee
commit b47fddd2cf
2 changed files with 10 additions and 3 deletions

View File

@ -2,7 +2,7 @@
## Unreleased
- Handle URL anchors (#83)
- Better handling of URL anchors (#83; #87)
- Fix bug in `Ex02_Basic.hs` (wasn't generating HTML files)
- Fix `runEmaPure` not generating routes
- Multisite

View File

@ -337,8 +337,15 @@ wsClientJS =
const origin = e.target.closest("a");
if (origin) {
if (window.location.host === origin.host && origin.getAttribute("target") != "_blank") {
switchRoute(origin.pathname, origin.hash);
e.preventDefault();
if (origin.getAttribute("href").startsWith("#")) {
// Switching to local anchor
window.history.pushState({}, "", window.location.pathname + origin.hash);
e.preventDefault();
}else{
// Switching to another route
switchRoute(origin.pathname, origin.hash);
e.preventDefault();
}
};
}
};