Page change without reloading page
This commit is contained in:
parent
4cd3402f9d
commit
9887857fc9
27
js/main.js
27
js/main.js
|
@ -15,13 +15,20 @@ $(document).ready(() => {
|
||||||
|
|
||||||
|
|
||||||
let path = document.location.pathname;
|
let path = document.location.pathname;
|
||||||
console.log("pathname: ", path);
|
|
||||||
|
|
||||||
if(path === "/" || path === "" || path === "/index.html"){
|
|
||||||
path = "/home";
|
|
||||||
}
|
|
||||||
|
|
||||||
setPage(path);
|
setPage(path);
|
||||||
|
|
||||||
|
$("nav > a").each((i, elmt) => {
|
||||||
|
const href = $(elmt).attr("href");
|
||||||
|
if(href[0] === "/"){
|
||||||
|
$(elmt).bind("click", () => {
|
||||||
|
// window.location.pathname = href;
|
||||||
|
history.pushState(null, null, href);
|
||||||
|
setPage(href);
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +44,10 @@ function setPage(path){
|
||||||
sanitize: false,
|
sanitize: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(path === "/" || path === "" || path === "/index.html"){
|
||||||
|
path = "/home";
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax("/pages"+path+".md")
|
$.ajax("/pages"+path+".md")
|
||||||
.done((res) => {
|
.done((res) => {
|
||||||
$("#article-container").html(res);
|
$("#article-container").html(res);
|
||||||
|
@ -54,8 +65,10 @@ function setPage(path){
|
||||||
return res;
|
return res;
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.fail((err) => {
|
||||||
|
$("#article-container").html(`<article><h1>Error ${err.status} :'(</h1><p>${err.statusText}<br/>${err.responseText}</p>`);
|
||||||
|
console.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue