Add PostInit in index.js/AbstractViews.js

This commit is contained in:
Xamora 2023-11-27 14:31:47 +01:00
parent b95bed8894
commit 8202a8b88d
2 changed files with 10 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import Dashboard from "./views/Dashboard.js";
import Posts from "./views/Posts.js";
import PostView from "./views/PostView.js";
import Settings from "./views/Settings.js";
import Chat from "./views/Chat.js";
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
@ -24,7 +25,8 @@ const router = async () => {
{ path: "/", view: Dashboard },
{ path: "/posts", view: Posts },
{ path: "/posts/:id", view: PostView },
{ path: "/settings", view: Settings }
{ path: "/settings", view: Settings },
{ path: "/chat", view: Chat },
];
// Test each route for potential match
@ -47,6 +49,8 @@ const router = async () => {
const view = new match.route.view(getParams(match));
document.querySelector("#app").innerHTML = await view.getHtml();
await view.postInit();
};
window.addEventListener("popstate", router);
@ -60,4 +64,4 @@ document.addEventListener("DOMContentLoaded", () => {
});
router();
});
});

View File

@ -3,6 +3,9 @@ export default class {
this.params = params;
}
async postInit() {
}
setTitle(title) {
document.title = title;
}
@ -10,4 +13,4 @@ export default class {
async getHtml() {
return "";
}
}
}