Skip to content

Problems when exporting the routes of a library #10750

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

Closed
danird1982 opened this issue May 9, 2018 · 3 comments
Closed

Problems when exporting the routes of a library #10750

danird1982 opened this issue May 9, 2018 · 3 comments

Comments

@danird1982
Copy link

danird1982 commented May 9, 2018

Versions

Angular CLI: 6.0.0
Node: 8.11.1
OS: win32 x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.6.0
@angular-devkit/build-angular      0.6.0
@angular-devkit/build-ng-packagr   0.6.0
@angular-devkit/build-optimizer    0.6.0
@angular-devkit/core               0.6.0
@angular-devkit/schematics         0.6.0
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.0.0
@schematics/angular                0.6.0
@schematics/update                 0.6.0
ng-packagr                         3.0.0-rc.2
rxjs                               6.1.0
typescript                         2.7.2
webpack                            4.6.0

Repro steps

We have a SPA that uses a library that exports a routing. The components are loaded lazy.

Code library:

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

const routes: Routes = [
  { path: 'screen1', loadChildren: 'lib1/screens/screen1/screen1.module#Screen1Module' },
  { path: 'screen2', loadChildren: 'lib1/screens/screen2/screen2.module#Screen2Module' }
];

const routing: ModuleWithProviders = RouterModule.forChild(routes);

@NgModule({
  imports: [],  
  exports: [
    RouterModule
  ]
})
export class Lib1RoutingModule {

  // Method export routing
  public static getRoutes() {
    return routing;
  }
}

We know that there is a problem when loading modules in a lazy way when they are outside the SPA and it is necessary to use a wrapper, but in this case it applies because the components are loaded where they have been defined.

The problem we have here is different and it occurs when the application is compiled and uses routing defined in the library. It is not able to load the component because it looks for its definition in the application itself and not in the library where it is defined.

Code SPA:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { Lib1RoutingModule } from 'lib1';
import { Comp1Component } from './comp1.component';

@NgModule({
  declarations: [
    Comp1Component,
  ],
  imports: [
   // Use routing library
    Lib1RoutingModule.getRoutes()
  ],
  providers: [],
  bootstrap: [Comp1Component],
  exports: [RouterModule]
})
export class Comp1Module {
}

Observed behavior

The error message when compiling is:

ERROR in Could not resolve module lib1/screens/screen1/screen1.module relative to /C/Environment/Angular/Angular6/repository/spa/src/app/comp1/comp1.module.ts

The module has been defined in the library but is looking for it in the SPA.

Desired behavior

Mention any other details that might be useful (optional)

@Bhargavi-Kotagaram
Copy link

Hi,

Is there any update on this issue? me too got stuck with this issue.

It will be great if some one can help on this issue

Thanks,

@alan-agius4
Copy link
Collaborator

Duplicate of #6373

@alan-agius4 alan-agius4 marked this as a duplicate of #6373 Nov 4, 2018
@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 8, 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

5 participants