Skip to content

Commit

Permalink
feat(router): add configurable title separator
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick de Wit committed Mar 20, 2018
1 parent ecec984 commit d2a1896
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/navigation-instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class NavigationInstruction {
}
}

_buildTitle(separator: string = ' | '): string {
_buildTitle(): string {
let title = '';
let childTitles = [];

Expand All @@ -257,19 +257,19 @@ export class NavigationInstruction {
let viewPortInstruction = this.viewPortInstructions[viewPortName];

if (viewPortInstruction.childNavigationInstruction) {
let childTitle = viewPortInstruction.childNavigationInstruction._buildTitle(separator);
let childTitle = viewPortInstruction.childNavigationInstruction._buildTitle();
if (childTitle) {
childTitles.push(childTitle);
}
}
}

if (childTitles.length) {
title = childTitles.join(separator) + (title ? separator : '') + title;
title = childTitles.join(this.router.separator) + (title ? this.router.separator : '') + title;
}

if (this.router.title) {
title += (title ? separator : '') + this.router.transformTitle(this.router.title);
title += (title ? this.router.separator : '') + this.router.transformTitle(this.router.title);
}

return title;
Expand Down
2 changes: 2 additions & 0 deletions src/router-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class RouterConfiguration {
} = {};
pipelineSteps: Array<{name: string, step: Function|PipelineStep}> = [];
title: string;
titleSeparator: string;
unknownRouteConfig: string|RouteConfig|((instruction: NavigationInstruction) => string|RouteConfig|Promise<string|RouteConfig>);
viewPortDefaults: {[name: string]: {moduleId: string|void; [key: string]: any}};

Expand Down Expand Up @@ -161,6 +162,7 @@ export class RouterConfiguration {

if (this.title) {
router.title = this.title;
router.titleSeparator = this.titleSeparator || ' | ';
}

if (this.unknownRouteConfig) {
Expand Down
7 changes: 6 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export class Router {
/**
* If defined, used in generation of document title for [[Router]]'s routes.
*/
title: string | undefined
title: string | undefined;

/**
* The separator used in the document title between [[Router]]'s routes.
*/
titleSeparator: string;

/**
* True if the [[Router]] has been configured.
Expand Down

0 comments on commit d2a1896

Please sign in to comment.