I am in the process of developing a web application using only Vanilla JavaScript, without any frameworks or libraries. I am following more of a 'React' style approach.
My goal is to load a view from my views/pages/dashboard.js file, display that view, and update the URL when the user clicks on the dashboard navigation link. Here is the navbar: https://codepen.io/Aurelian/pen/EGJvZW.
I am considering integrating the sub-navigation items into the routing system. If the user is in the GitHub folder under profile, how can I reflect that in the URL?
How can I implement routing for this scenario?
You can find the GitHub repository here: https://github.com/AurelianSpodarec/JS_GitHub_Replica/tree/master/src/js
This is my current attempt:
document.addEventListener("DOMContentLoaded", function() {
var Router = function (name, routes) {
return {
name: name,
routes: routes
}
};
var view = document.getElementsByClassName('main-container');
var myRouter = new Router('myRouter', [
{
path: '/',
name: "Dashboard"
},
{
path: '/todo',
name: "To-Do"
},
{
path: '/calendar',
name: "Calendar"
}
]);
var currentPath = window.location.pathname;
if (currentPath === '/') {
view.innerHTML = "You are on the Dashboard";
console.log(view);
} else {
view.innerHTML = "you are not";
}
});