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

Router Store: Return resolved route title via selectTitle selector #3622

Closed
1 of 2 tasks
markostanimirovic opened this issue Oct 20, 2022 · 1 comment · Fixed by #3648
Closed
1 of 2 tasks

Router Store: Return resolved route title via selectTitle selector #3622

markostanimirovic opened this issue Oct 20, 2022 · 1 comment · Fixed by #3648

Comments

@markostanimirovic
Copy link
Member

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

router-store

Information

The selectTitle selector should return resolved route title when a custom title resolver is used. In v14, it selects the title defined as a static string in route configuration.

Describe any alternatives/workarounds you're currently using

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@enten
Copy link

enten commented Oct 25, 2022

FYI: we can get the title resolved with TitleStrategy.getResolvedTitleForRoute(snapshot: ActivatedRouteSnapshot).

Example of MinimalRouterStateSerializer using the TitleStrategy to resolve the title:

export class MinimalRouterStateSerializer
  implements RouterStateSerializer<MinimalRouterStateSnapshot>
{
  constructor(private titleStrategy: TitleStrategy) {}

  serialize(routerState: RouterStateSnapshot): MinimalRouterStateSnapshot {
    return {
      root: this.serializeRoute(routerState.root),
      url: routerState.url,
    };
  }

  private serializeRoute(
    route: ActivatedRouteSnapshot
  ): MinimalActivatedRouteSnapshot {
    const children = route.children.map((c) => this.serializeRoute(c));
    const routeTitle = this.titleStrategy.getResolvedTitleForRoute(route);
    return {
      params: route.params,
      data: route.data,
      url: route.url,
      outlet: route.outlet,
      routeConfig: route.routeConfig
        ? {
            path: route.routeConfig.path,
            pathMatch: route.routeConfig.pathMatch,
            redirectTo: route.routeConfig.redirectTo,
            outlet: route.routeConfig.outlet,
            title: routeTitle,
          }
        : null,
      queryParams: route.queryParams,
      fragment: route.fragment,
      firstChild: children[0],
      children,
    };
  }
}

brandonroberts pushed a commit that referenced this issue Nov 5, 2022
Closes #3622

BREAKING CHANGES:

Property `title: string | undefined` is added to the `MinimalActivatedRouteSnapshot` interface.

BEFORE:

The `MinimalActivatedRouteSnapshot` interface doesn't contain the `title` property.

AFTER:

The `MinimalActivatedRouteSnapshot` interface contains the required `title` property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants