同构 JavaScript 应用开发全解析
1. 应用导航与控制器处理
在开发应用时,导航逻辑和控制器的处理至关重要。下面是一段关键代码,展示了如何处理导航和控制器的切换:
let previousController = this.controller;
this.controller = this.createController(url)
// if a controller was created then proceed with navigating
if (this.controller) {
// request and reply stubs
const request = () => {};
const reply = replyFactory(this);
if (push) {
history.pushState({}, null, url);
}
// execute controller action
this.controller.index(this, request, reply, (err) => {
if (err) {
return reply(err);
}
let targetEl = document.querySelector(this.options.target);
if (previousController) {
previousController.detach(targetEl);
}
// render controller response
超级会员免费看
订阅专栏 解锁全文
29

被折叠的 条评论
为什么被折叠?



