Skip to content

Commit

Permalink
Updated example to use non-hash based routing.
Browse files Browse the repository at this point in the history
  • Loading branch information
razaibi authored Sep 8, 2024
1 parent 2aebb5f commit a0c3ff2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
18 changes: 15 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<ul class="menu_holder">
<li> examples
<div class="menu_li_content">
<a href="#/">popular people</a>
<a href="#/rockets">top rockets</a>
<a href="#/prices">price card</a>
<a id="peopleLink">popular people</a>
<a id="rocketLink">top rockets</a>
<a id="priceLink">price card</a>
</div>
</li>

Expand Down Expand Up @@ -82,6 +82,18 @@
}
*/

document.getElementById('peopleLink').addEventListener("click", function(){
wuObject.navigateTo('/');
});

document.getElementById('rocketLink').addEventListener("click", function(){
wuObject.navigateTo('/rockets');
});

document.getElementById('priceLink').addEventListener("click", function(){
wuObject.navigateTo('/prices');
});


</script>

Expand Down
24 changes: 15 additions & 9 deletions example/js/Wirup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ wirup.prototype = (function () {
return httpRequest.responseText;
});
},
_appLocation = window.location.hash.split("#")[1],
_appLocation = window.location.pathname,
_views,
_registerViews = () => {
return _wijax(
Expand All @@ -46,8 +46,8 @@ wirup.prototype = (function () {
return new Promise((resolve, reject) => {
let _index;
var _url = _appLocation;
if (_appLocation === undefined || _appLocation == "/") {
window.location = "/#/";
if (_appLocation === undefined) {
window.location = "/";
}
if (_views) {
for (var i = 0; i <= _views.length - 1; i++) {
Expand Down Expand Up @@ -76,13 +76,18 @@ wirup.prototype = (function () {
);
},
_bindRouter = () => {
window.onhashchange = function () {
if (window.location.hash != _appLocation) {
_appLocation = window.location.hash.split("#")[1];
_init();
}
window.onpopstate = (event) => {
_appLocation = window.location.pathname; // Handle back/forward button
_init();
};
},
_navigateTo = (url) => {
history.pushState(null, null, url); // Update URL without reloading
_appLocation = url; // Update internal app location
_getTemplate("contentBody").then(() => {
_renderViewComponents();
});
},
_dataStore = {},
_components = {},
_loadObserver = {},
Expand Down Expand Up @@ -289,6 +294,7 @@ wirup.prototype = (function () {
registerAction: _registerAction,
buildComponent: _buildComponent,
buildComponents: _buildComponents,
navigateTo: _navigateTo,
registerData: _registerData,
addData: _addData,
findIndexByKey: _findIndexByKey,
Expand All @@ -300,4 +306,4 @@ wirup.prototype = (function () {
init: _init,
};
})();
window.wuObject = new wirup();
window.wuObject = new wirup();
2 changes: 1 addition & 1 deletion example/js/Wirup.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0c3ff2

Please sign in to comment.