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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadcrumbs are not displayed for lazy loaded module #149

Closed
luizagabriela opened this issue Oct 12, 2022 · 3 comments
Closed

Breadcrumbs are not displayed for lazy loaded module #149

luizagabriela opened this issue Oct 12, 2022 · 3 comments
Labels
bug Something isn't working no-issue-activity

Comments

@luizagabriela
Copy link

馃悶 Bug report

Description

I'm trying to display the breadcrumb for a lazy loaded module but there is an error in the breadcrumb.service file on line 274 related to the _loadedConfig. The _loadedConfig property is undefined.

I'm using the changes from this Pull request , because I have to use the new feature of displaying the breadcrumb using a resolver.

This is the piece of code from the breadcrumb service where the _loadedConfig is undefined. ( baseChild = routeConfig._loadedConfig.routes.find(); )


 private mergeWithBaseChildData(
    routeConfig,
    config: BreadcrumbConfig
  ): BreadcrumbObject {
    if (!routeConfig) {
      return this.extractObject(config);
    }

    let baseChild;
    if (routeConfig.loadChildren) {
      // To handle a module with empty child route
      baseChild = routeConfig._loadedConfig.routes.find(
        (route) => route.path === ''
      );
    } else if (routeConfig.children) {
      // To handle a component with empty child route
      baseChild = routeConfig.children.find((route) => route.path === '');
    }

    const childConfig = baseChild?.data?.breadcrumb;
    return childConfig
      ? this.mergeWithBaseChildData(baseChild, {
          ...this.extractObject(config),
          ...this.extractObject(childConfig),
        })
      : this.extractObject(config);
  }

Angular Version: "14.2"
Angular Router Version: "14.2"

I found a fix for this bug. There is another property of routeConfig that is of Router type and is called _loadedRoutes. This object contains the component and path of the route and can be used instead of _loadedConfig property.


private mergeWithBaseChildData(
    routeConfig,
    config: BreadcrumbConfig
  ): BreadcrumbObject {
    if (!routeConfig) {
      return this.extractObject(config);
    }

    let baseChild;
    if (routeConfig.loadChildren) {
      // To handle a module with empty child route
      baseChild = routeConfig._loadedRoutes.find(
        (route) => route.path === ''
      );
    } else if (routeConfig.children) {
      // To handle a component with empty child route
      baseChild = routeConfig.children.find((route) => route.path === '');
    }

    const childConfig = baseChild?.data?.breadcrumb;
    return childConfig
      ? this.mergeWithBaseChildData(baseChild, {
          ...this.extractObject(config),
          ...this.extractObject(childConfig),
        })
      : this.extractObject(config);
  }

This change is needed to display the breadcrumbs in the lazy loaded modules.

What do you think? Can these changes be made as part of the pull request related to the routeSnapshot data available in breadcrumb function?

Thanks!

@luizagabriela luizagabriela added the bug Something isn't working label Oct 12, 2022
@github-actions
Copy link

Hello 馃憢 @luizagabriela
Thank you for raising an issue. We will investigate into the issue and get back to you as soon as possible. Please make sure you have given us as much context as possible.
Feel free to raise a PR if you can fix the issue. Check the local development guide

@stale
Copy link

stale bot commented Feb 11, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Feb 11, 2023
@stale stale bot closed this as completed Jun 11, 2023
@udayvunnam udayvunnam reopened this Mar 17, 2024
@stale stale bot removed the wontfix This will not be worked on label Mar 17, 2024
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working no-issue-activity
Projects
None yet
Development

No branches or pull requests

2 participants