router icon indicating copy to clipboard operation
router copied to clipboard

Appending a value to the end of the config.title instead of the beginning

Open alsoicode opened this issue 10 years ago • 5 comments

I would like to set a default title in the Aurelia config and then append values to the end of it in views, but Aurelia seems to want to append values to the beginning of the config.title value.

I have this question currently open on Stack Overflow: http://stackoverflow.com/questions/32802219/appending-a-value-to-the-aurelia-router-config-title

alsoicode avatar Sep 29 '15 03:09 alsoicode

Solved:

In main.js, override buildTitle:

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;

alsoicode avatar Sep 29 '15 13:09 alsoicode

We should make it easier to customize this behavior.

bryanrsmith avatar Sep 29 '15 16:09 bryanrsmith

Perhaps a config option to append or prepend the route title?

alsoicode avatar Sep 29 '15 16:09 alsoicode

That sounds reasonable. On Sep 29, 2015 12:43 PM, "Brandon Taylor" [email protected] wrote:

Perhaps a config option to append or pre-pend the route title?

— Reply to this email directly or view it on GitHub https://github.com/aurelia/router/issues/218#issuecomment-144110490.

EisenbergEffect avatar Sep 29 '15 16:09 EisenbergEffect

The NavigationInstruction._buildTitle function has as a separator parameter. From what I can tell only the default value separator = " | " is used.

Please would you consider allowing the separator to be configured as well?

mattbrooks2010 avatar Sep 13 '16 10:09 mattbrooks2010