Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Add a namspace
- window.MyWebApp = {};
- var Routes = {
- Home: {
- init: function () {
- // controller-wide code
- },
- NewJsPage: function () {
- // action-specific code
- import("./newJsPage").then((module) => {
- window.MyWebApp.newJsPage = module.newJsPage;
- });
- },
- Privacy: function () {
- // Privacy action code
- }
- }
- };
- var Router = {
- exec: function (controller, action) {
- action = action === undefined ? "init" : action;
- if (controller !== "" && Routes[controller] && typeof Routes[controller][action] === "function") {
- Routes[controller][action]();
- }
- },
- init: function () {
- let body = document.body;
- let controller = body.getAttribute("data-controller");
- let action = body.getAttribute("data-action");
- Router.exec(controller);
- Router.exec(controller, action);
- }
- };
- $(function () {
- //run this when the DOM is ready
- Router.init();
- });
Add Comment
Please, Sign In to add comment