Spaces:
Build error
Build error
Commit ·
f14468a
1
Parent(s): 48f3ef2
fix(H-09): add hashchange event listener to Router.init() -- direct URL navigation now updates the view
Browse files- frontend/js/router.js +8 -4
frontend/js/router.js
CHANGED
|
@@ -53,12 +53,16 @@ const Router = {
|
|
| 53 |
},
|
| 54 |
|
| 55 |
init: () => {
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
const hash = window.location.hash.slice(1) || "/";
|
| 58 |
Router.navigate(hash, false);
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
},
|
| 63 |
};
|
| 64 |
|
|
|
|
| 53 |
},
|
| 54 |
|
| 55 |
init: () => {
|
| 56 |
+
// H-09 FIX: listen to both popstate (browser back/forward) AND
|
| 57 |
+
// hashchange (direct URL entry, anchor link clicks). Both are needed
|
| 58 |
+
// for a hash-router. popstate alone misses direct URL navigation.
|
| 59 |
+
const _handleNav = () => {
|
| 60 |
const hash = window.location.hash.slice(1) || "/";
|
| 61 |
Router.navigate(hash, false);
|
| 62 |
+
};
|
| 63 |
+
window.addEventListener("popstate", _handleNav);
|
| 64 |
+
window.addEventListener("hashchange", _handleNav);
|
| 65 |
+
_handleNav();
|
| 66 |
},
|
| 67 |
};
|
| 68 |
|