Skip to content

Use loadChildren load sub module, when visit sub route page, submodule's dependency module will repeat new. #13885

Closed

Description

@hstarorg

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
Use loadChildren loaded module will repeat new dependencies module.

Expected behavior
Not repeat new, use the singleton module.

Minimal reproduction of the problem with instructions

Define a child module, set more than one route, like this:

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import {
  Page1Component,
  Page2Component
} from './pages';

const appRoutes: Routes = [
  { path: '', component: Page1Component },
  { path: 'page2', component: Page2Component },
];

export const routing: ModuleWithProviders = RouterModule.forChild(appRoutes);

In the parent routing config, dynamic load the child module, like this:

import { SubModule } from 'modules/demo1';
const appRoutes: Routes = [{
  path: '', component: LayoutComponent,
  children: [
    { path: 'demo1', loadChildren: () => AppModule },
    { path: '**', component: NotFoundComponent }
  ]
}];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, { useHash: true });

When visit /demo1 and /demo1/page1, the sub module's dependency module will also init.

What is the motivation / use case for changing the behavior?
When route change in dynamic loaded module.

Please tell us about your environment:
It is not important.

  • Angular version:
    2.4.1

Activity

  1. DzmitryShylovich commented on Jan 12, 2017

    @DzmitryShylovich
    Contributor

    Duplicate of #12889

  2. hstarorg commented on Jan 12, 2017

    @hstarorg
    Author

    @DzmitryShylovich Caused a new problem, that can't use common-module's service to store data.

  3. mhevery commented on Jan 13, 2017

    @mhevery
    Contributor

    @hstarorg whey can't you use common-module service to store data?

  4. hstarorg commented on Jan 16, 2017

    @hstarorg
    Author

    @mhevery Only common-module is dynamic load will has the bug.

  5. hstarorg commented on Feb 15, 2017

    @hstarorg
    Author

    @DzmitryShylovich Would you tell me which version will fix this bug?

  6. DzmitryShylovich commented on Feb 15, 2017

    @DzmitryShylovich
    Contributor

    @hstarorg 4.0 (not sure about 2.x)

  7. hstarorg commented on Feb 15, 2017

    @hstarorg
    Author

    @DzmitryShylovich 4.0.0-beta.7 also has this bug,

  8. DzmitryShylovich commented on Feb 15, 2017

    @DzmitryShylovich
    Contributor

    4.0 final...

  9. hstarorg commented on Feb 15, 2017

    @hstarorg
    Author

    @DzmitryShylovich ok, I must waiting a long time.

  10. added a commit that references this issue on Apr 7, 2017
    d415ea2
  11. added a commit that references this issue on Aug 11, 2017
    2186d0d
  12. added a commit that references this issue on Aug 28, 2017
    0888a00
  13. angular-automatic-lock-bot commented on Sep 11, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  14. locked and limited conversation to collaborators on Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions