6

I have a customer module with customer-routing module:

const routes: Routes = [
  {
    path: '', component: CustomerComponent,
    children: [
      { path: 'edit', component: EditCustomerComponent }
    ]
  }
];

And this is my app-routing module:

const routes: Routes = [
  { path: 'customers/:id', loadChildren: './customer/customer.module#CustomerModule' },
  { path: 'login', component: LoginComponent}
];

But when I follow such path customers/3/edit it shows me always CustomerComponent not EditCustomerComponent.

Maybe lazy loading doesn't work?

PS: I am using angular 6.1.0

Update: My customer module

import {ReactiveFormsModule} from '@angular/forms';
import {CustomerComponent} from './customer.component';
import {EditCustomerComponent} from './edit-customer.component';

@NgModule({
  imports: [
    CommonModule,
    CustomerRoutingModule,
    ReactiveFormsModule
  ],
  declarations: [CustomerComponent, EditCustomerComponent]
})
export class CustomerModule { }
5
  • Can you enable tracing and show the output? Commented Sep 23, 2018 at 10:50
  • also, how is defined your CustomerModule? Commented Sep 23, 2018 at 10:51
  • @LazarLjubenović Added this config but I dont see anything in console Commented Sep 23, 2018 at 10:58
  • @Pac0 Added my customer module Commented Sep 23, 2018 at 11:00
  • 1
    Do you have a router-outlet inside the HTML of CustomerComponent ? For me the router configuration seem to be fine Commented Sep 23, 2018 at 12:11

1 Answer 1

4

You don't have to put edit route under children. Your customer-routing module would simply look like this:

const routes: Routes = [
  { path: '', component: CustomerComponent },
  { path: 'edit', component: EditCustomerComponent }
];

Also make sure to check whether this routes array has been imported using forChild function in your customer-routing module like this:

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class CustomerRoutingModule { }

Hope this should solve your routing issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.