Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add an option to reverse the order of the route titles #7007

Open
cedx opened this issue Jul 22, 2024 · 0 comments
Open

feat: Add an option to reverse the order of the route titles #7007

cedx opened this issue Jul 22, 2024 · 0 comments
Assignees
Labels
area:fast-router Pertains to fast-router community:request Issues specifically reported by a member of the community. feature A new feature status:planned Work is planned

Comments

@cedx
Copy link

cedx commented Jul 22, 2024

🙋 Feature Request

Most websites, and even Windows applications, put the root title as the last component.
The general pattern is: <document/page name> - <application name> or <routeTitle> - <rootTitle>
(like: "Material Symbols and Icons - Google Fonts" or "Document1 - Word")

But the router produces the opposite title pattern:
<rootTitle> - <routeTitle>

So, I would like an option to set the direction of the title order.
This could also be interesting for RTL languages.

🤔 Expected Behavior

The document title follows this pattern if the newly created option is set:
<child2> - <child1> - <root>

😯 Current Behavior

The document title follows this pattern:
<root> - <child1> - <child2>

💁 Possible Solution

Add an option to the DefaultTitleBuilder constructor? And let folks override the RouterConfiguration.createTitleBuilder() method...

💻 Examples

Currently, I use a custom TitleBuilder just for this purpose:

class TitleBuilder {
	readonly #fragmentSeparator: string;
	readonly #reverseOrder: boolean;
	readonly #segmentSeparator: string;

	constructor(segmentSeparator = " - ", fragmentSeparator = ":", reverseOrder = false) {
		this.#fragmentSeparator = fragmentSeparator;
		this.#reverseOrder = reverseOrder;
		this.#segmentSeparator = segmentSeparator;
	}

	buildTitle(rootTitle: string, routeTitles: string[][]) {
		const segments = [rootTitle];
		for (const fragments of routeTitles) segments.push(fragments.filter(title => title.length).join(this.#fragmentSeparator));

		const titles = segments.filter(title => title.length);
		if (this.#reverseOrder) titles.reverse();
		return titles.join(this.#segmentSeparator);
	}

	joinTitles(parentTitle: string, childTitle: string): string {
		const titles = [parentTitle, childTitle].filter(title => title.length);
		if (this.#reverseOrder) titles.reverse();
		return titles.join(this.#segmentSeparator);
	}
}
@cedx cedx added the status:triage New Issue - needs triage label Jul 22, 2024
@KingOfTac KingOfTac changed the title [FAST Router] Add an option to reverse the order of the route titles feat: Add an option to reverse the order of the route titles Sep 5, 2024
@KingOfTac KingOfTac self-assigned this Sep 5, 2024
@KingOfTac KingOfTac added feature A new feature status:planned Work is planned community:request Issues specifically reported by a member of the community. area:fast-router Pertains to fast-router and removed status:triage New Issue - needs triage labels Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:fast-router Pertains to fast-router community:request Issues specifically reported by a member of the community. feature A new feature status:planned Work is planned
Projects
None yet
Development

No branches or pull requests

2 participants