Skip to content

Creating a module with --route & --routing creates duplicated & errored code #17139

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
Maryannah opened this issue Mar 3, 2020 · 5 comments · Fixed by #23486
Closed

Creating a module with --route & --routing creates duplicated & errored code #17139

Maryannah opened this issue Mar 3, 2020 · 5 comments · Fixed by #23486
Assignees
Labels
2022Q3 Fixit Candidates for the Q3 2022 fix-it area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@Maryannah
Copy link

Maryannah commented Mar 3, 2020

🐞 bug report

Affected Package

The issue is caused by the schematics that create a module

Is this a regression?

I do not know, I have never tried it before

Description

when running a command to create a module with --route & --routing, the code gets duplicated : there are routes in the *.module.ts along with the *-routing.module.ts

🔬 Minimal Reproduction

I didn't manage to create a stackblitz, but here are the commands to reproduce it locally.
npx create-nx-workspace@latest workspace
cd workspace
ng add @nrwl/angular --defaults
ng g @nrwl/angular:application app --style scss --routing true --prefix app
ng g m home --route home --module app.module.ts --routing true --project app

🌍 Your Environment

Angular Version:


    "@angular/animations": "^9.0.0",
    "@angular/cdk": "^9.0.0",
    "@angular/common": "^9.0.0",
    "@angular/compiler": "^9.0.0",
    "@angular/core": "^9.0.0",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "^9.0.0",
    "@angular/material": "^9.0.0",
    "@angular/platform-browser": "^9.0.0",
    "@angular/platform-browser-dynamic": "^9.0.0",
    "@angular/router": "^9.0.0",
    "@nrwl/angular": "^9.0.4",

Anything else relevant?

I do not know if this is wanted or not, and I do not know which one is the best practice (the one to keep).

Here is a picture of the issue, in case it helps : you can see routes on the module, but also a routing module that is imported with it.

image

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Mar 3, 2020

Hi @Maryannah, I tried this locally and while the second part is a bug, I was unable to reproduce the first issue with the steps provided.

The resulted module looks like the below without the routing flag

const routes: Routes = [
  { path: '', component: HomeComponent }
];

@NgModule({
  declarations: [HomeComponent],
  imports: [
    CommonModule,
    RouterModule.forChild(routes)
  ]
})
export class HomeModule { }

@Maryannah
Copy link
Author

@alan-agius4 I have followed the steps again and here is the result :

image

If I remove the routing flag :

image

It seems that the second (semi-colon) and third (schematics config not applied) issues are with my own repository, I will look into that myself ! I am removing them from my original issue

@alan-agius4
Copy link
Collaborator

Hi @Maryannah, can you please update the issue title and description accordingly as it seems that you deleted the details of the actual bug?

Thanks.

@Maryannah
Copy link
Author

@alan-agius4 I have removed what is related to my own repository and kept the issue as it was found originally.

I am adding a screenshot to picture it if needed, but that's all the issue, the duplication of the routes !

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jul 1, 2022
…o `RoutingModule`

Prior to this commit, we defined routes in two places example:
```ts
@NgModule({
  declarations: [
    HomeComponent
  ],
  imports: [
    CommonModule,
    RouterModule.forChild(routes),
    HomeRoutingModule
  ]
})
export class HomeModule { }
```

Closes angular#17139
@alan-agius4 alan-agius4 added the 2022Q3 Fixit Candidates for the Q3 2022 fix-it label Jul 1, 2022
@alan-agius4 alan-agius4 self-assigned this Jul 1, 2022
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jul 6, 2022
…o `RoutingModule`

Prior to this commit, we defined routes in two places example:
```ts
@NgModule({
  declarations: [
    HomeComponent
  ],
  imports: [
    CommonModule,
    RouterModule.forChild(routes),
    HomeRoutingModule
  ]
})
export class HomeModule { }
```

Closes angular#17139
alan-agius4 added a commit that referenced this issue Jul 6, 2022
…o `RoutingModule`

Prior to this commit, we defined routes in two places example:
```ts
@NgModule({
  declarations: [
    HomeComponent
  ],
  imports: [
    CommonModule,
    RouterModule.forChild(routes),
    HomeRoutingModule
  ]
})
export class HomeModule { }
```

Closes #17139
alan-agius4 added a commit that referenced this issue Jul 6, 2022
…o `RoutingModule`

Prior to this commit, we defined routes in two places example:
```ts
@NgModule({
  declarations: [
    HomeComponent
  ],
  imports: [
    CommonModule,
    RouterModule.forChild(routes),
    HomeRoutingModule
  ]
})
export class HomeModule { }
```

Closes #17139

(cherry picked from commit 9e31524)
@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 Aug 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2022Q3 Fixit Candidates for the Q3 2022 fix-it area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
3 participants