{
route: 'content/:id',
name: 'Details',
title: 'Details',
viewPorts: { main: { moduleId: './admin/content/details' }, aside: { moduleId: './admin/content/aside' } },
settings: { menu:menuSection.content, access: { controller: 'content', action: 'get' } }
},
{
route: 'content/:id',
name: 'Add',
viewPorts: { main: { moduleId: './admin/content/details' }, aside: { moduleId: './admin/content/aside' } },
settings: { menu:menuSection.content, access: { controller: 'content', action: 'get' } }
title: 'Add',
href: 'content/0',
nav: true
}
import {Router} from 'aurelia-router';
activate(){
if (this.id === 0) {
this.router.title = "Add";
} else {
this.router.title = "Edit";
}
}
我正在尝试更改标题,因为它目前正在为新内容和更新内容添加“添加”。我也尝试过routeConfig(它引发了一个错误:未处理的promise拒绝TypeError:无法读取未定义的属性'navModel'),只是想知道我是否接近,找到正确的代码?我需要做一些推动this.router.push吗?
我相信我可能需要使用UpdateTitle做一些事情:
class UpdateTitle {
run(routingContext, next, routeConfig) {
var instr = routingContext.nextInstructions.find(i => i.params.id !== undefined && i.params.id !== 0 && i.params.id !== '');
if(instr !== undefined) {
Unsure what to do here?//routeConfig.navModel.title("TEST");
debugger;
}
return next();
}
}
答案 0 :(得分:1)
如果您想从激活功能更改标题,请尝试
activate(params, routeConfig) {
routeConfig.navModel.title = 'Edit';
}