Skip to content

Expose resolved route title #46825

@EmmanuelRoux

Description

@EmmanuelRoux

Which @angular/* package(s) are relevant/related to the feature request?

router

Description

Since Angular 14, router has a new mechanism to update page title from route config. The route can either be a static string or resolved in the same way as resolve data.

But the resolved route title is not exposed and inaccessible from client application (it seems the title is actually stored in the resolved Data, but using a private Symbol so it can't be accessed properly).

Proposed solution

Expose a new title property on ActivatedRoute and ActivatedRouteSnapshot, just like existing params, data...

Alternatives considered

Alternative 1: Expose the internal RouteTitle symbol used to store title in Data, but this is probably not wanted because it would expose an implementation detail.

Alternative 2: Use TitleStrategy.buildTitle(snapshot: RouterStateSnapshot) or, better, TitleStrategy.getResolvedTitleForRoute(snapshot: ActivatedRouteSnapshot). But this has following drawbacks:

  • TitleStrategy must be injected where we need to (only) read the route title, which is not its primary purpose...
  • TitleStrategy is not very convenient to inject, because in default case, DefaultTitleStrategy is used but is not available through DI with TitleStrategy token. To get the actual strategy used, one must retrieve it from Router.titleStrategy.
  • This is inconsistent with existing public api of ActivatedRoute/ActivatedRouteSnapshot

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions