将值附加到Aurelia路由器config.title [英] Appending a value to the Aurelia router config.title
问题描述
我想为我的Aurelia应用程序设置一个基本标题值,然后根据活动的路由为其添加一个值.
I want to set a base title value for my Aurelia application and then append a value to it based on the route that is active.
我的路由器配置为:
export class App {
configureRouter(config, router) {
config.title = 'Brandon Taylor | Web Developer | Graphic Designer';
config.map([
. . .
{ route: 'work', name: 'work', moduleId: 'work', nav: true, title: ' | work' },
. . .
]);
this.router = router;
}
}
Aurelia希望将title
导航参数附加到config.title
的开始,但是我想在结束处使用.
Aurelia wants to append the title
navigation parameter to the beginning of the config.title
, but I would like it at the end.
我尝试在视图模型中进行覆盖:
I've tried doing an override in the view model:
export class Work {
activate(params, routeConfig, navigationInstruction) {
routeConfig.navModel.router.title += ' | work';
};
}
但这会导致:
Brandon Taylor | Web Developer | Graphic Designer | work | work | work ...
每个路由请求上的
.我究竟做错了什么?或者如何将route title
属性附加到config.title
的 end 而不是开头?
on each routing request. What am I doing wrong? or how can I append the route title
attribute to the end of the config.title
instead of the beginning?
推荐答案
感谢@Jeremy Danyow向我指出正确的方向.
Thanks for pointing me in the right direction @Jeremy Danyow.
我最终得到的是:
import {NavigationContext} from 'aurelia-router';
NavigationContext.prototype.standardBuildTitle = NavigationContext.prototype.buildTitle;
function buildTitle(separator=' | ') {
var titleValues = this.standardBuildTitle(separator).split(separator),
routeTitle = titleValues[0],
configTitle = titleValues.slice(1);
configTitle.push(routeTitle);
return configTitle.join(separator);
}
NavigationContext.prototype.buildTitle = buildTitle;
原因如下:
config.title = 'Brandon Taylor | Web Developer | Graphic Designer'
并致电:
return standardTitle.split(separator).reverse().join(separator);
导致:
Graphic Designer | Web Developer | Brandon Taylor | about
代替:
Brandon Taylor | Web Developer | Graphic Designer | about
这篇关于将值附加到Aurelia路由器config.title的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!