Answer the question
In order to leave comments, you need to log in
How not to load everything at once using systemjs as a script loader?
Suppose there are many sections on the site, each of them is responsible for some class-processor of a particular page.
When we go to any page, the main file is triggered which initializes the router let router = new Router(); which determines on which page which handler class needs to be initialized (i.e. create its instance and can execute some method). It looks like this:
import {HomePageController} from "../modules/homePageController";
import {page1Controller} from "../modules/page1Controller";
import {page2Controller} from "../modules/page2Controller";
import {page3Controller} from "../modules/page3Controller";
import {page4Controller} from "../modules/page4Controller";
export class RouterMap{
constructor(){
return this;
}
protected routes = {
"/:hl/$": {
controller: HomePageController,
handlerMethod: "onInit",
onLeaveHandlerMethod: "onLeave"
},
"/:hl/p1": {
controller: page1Controller,
handlerMethod: "onInit",
onLeaveHandlerMethod: "onLeave"
},
"/:hl/p2": {
controller: page2Controller,
handlerMethod: "onInit",
onLeaveHandlerMethod: "onLeave"
},
"/:hl/p3": {
controller: page3Controller,
handlerMethod: "onInit"
},
"/:hl/p4": {
controller: page4Controller,
handlerMethod: "onInit",
route:{
"/:id": {
handlerMethod: "onInit"
}
}
}
};
}
Answer the question
In order to leave comments, you need to log in
Maybe I misunderstood the question, correct me a little.
For dynamic use, use getters:
"/:hl/p12": {
get controller(): {
return page1Controller || page2Controller; //тут могут быть любые условия
},
handlerMethod: "onInit",
onLeaveHandlerMethod: "onLeave"
},
let pageController;
if(true) {
pageController = require("../modules/page1Controller"). page1Controller;
} else {
pageController = require("../modules/page2Controller"). page2Controller;
}
"/:hl/p12": {
controller: pageController,
handlerMethod: "onInit",
onLeaveHandlerMethod: "onLeave"
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question