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

Lazy Loaded Module does not work with lazy routing #19520

Closed
Jonathan002 opened this issue Oct 3, 2017 · 5 comments
Closed

Lazy Loaded Module does not work with lazy routing #19520

Jonathan002 opened this issue Oct 3, 2017 · 5 comments

Comments

@Jonathan002
Copy link

Jonathan002 commented Oct 3, 2017

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Problem: I have a lazy module that needs to use the app popup router (secondary named outlet) in my app.component.html.

Expected behavior

Lazy module can use the popup router in my app.component.html.

Minimal reproduction of the problem with instructions

I have the following in my app component template:

src/app/app.component.html

    <!-- Primary Router -->
    <router-outlet id="main-router"></router-outlet>
    
    <!-- Popup Router -->
    <router-outlet name="app-popup"></router-outlet> <!-- <====== -->

My App Module and it's routes:

/src/app/app-routing.module.ts

const appRoutes: Routes = [
      { path: 'lazy',  loadChildren: 'app/lazy/lazy.module#LazyModule' }, // <--------
    ];
    @NgModule({
      imports: [
        CommonModule,
        RouterModule.forRoot(appRoutes),
      ],
      exports: [
        RouterModule
      ],
    })
    export class AppRoutingModule { }

/src/app/app.module.ts

    @NgModule({
      declarations: [AppComponent],
      imports: [
        BrowserModule,
        AppRoutingModule
      ],
      bootstrap: [AppComponent]
    })
    export class AppModule {}

My Lazy Module and it's routes:

/src/app/lazy/lazy.module.ts

    const lazyRoutes: Routes = [
      { path: 'lazy-popup', outlet: 'app-popup', component: LazyPopupComponent },
      { path: '', component: LazyComponent }
    ];
    @NgModule({
      imports: [
        RouterModule.forChild(lazyRoutes)
      ],
      exports: [
          RouterModule
      ]
    })
    export class LazyRoutingModule {}

/src/app/lazy/lazy.module.ts

    @NgModule({
      imports: [
        CommonModule,
        AppSharedModule,
        LazyRoutingModule
      ],
      declarations: [
        LazyComponent,
        LazyPopupComponent
      ],
      exports: [
        LazyPopupComponent,
        LazyRoutingModule,
      ]
    })
    export class LazyModule {}

How I navigate:

I navigate to the route like this:

/src/app/lazy/lazy.component.html

    <button [routerLink]=" [ '', { outlets: { 'app-popup': ['lazy-popup'] } }] "></button>

I can't seem to get it to work as I get this error:

    core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: Cannot match 
    any routes. URL Segment: 'lazy-popup'.

Note that this works perfectly though if I import the LazyModule in AppModule below:

    @NgModule({
      declarations: [AppComponent],
      imports: [
        BrowserModule,
        AppRoutingModule,
        LazyModule // <-- The routes work now.. But.. this should be lazy.. : (
      ],
      bootstrap: [AppComponent]
    })
    export class AppModule {}

Although this defeats the purpose of it being a lazy loaded module. So how can I get the lazy loaded module use the secondary router-outlet named 'app-popup' that exist in the app components html template?

What is the motivation / use case for changing the behavior?

Getting a lazy module to use a single app wide secondary outlet as a popup.

Environment

Angular-Cli project


Angular version: 4.2.4


Browser:
- [ x ] Chrome (desktop) version 61.0.3163.100
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  Mac 

Others:

@Jonathan002 Jonathan002 changed the title Lazy Loaded Module does not support lazy routing Lazy Loaded Module does not work with lazy routing Oct 3, 2017
@codart1
Copy link

codart1 commented Oct 10, 2017

This issue is really anoying

@royling
Copy link
Contributor

royling commented Oct 17, 2017

Duplicate with #10981

@mlc-mlapis
Copy link
Contributor

@Jonathan002 ... use the equivalent solution like described here by using createEmbeddedView https://stackblitz.com/edit/adv-ng-left-nav

@jasonaden
Copy link
Contributor

Closing as a duplicate as well as needing a reproduction (use Plunker or Stackblitz). If you would would like to create a repro that's different than #10981 and not solved by the referenced stackblitz above, please create a new issue.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants