3

I'm using nested routes in my Angular 4 application. They are structured as follows:

routes = [
  {
    path: 'parent',
    component: ParentComponent,
    children: [
      {
        path: 'child',
        component: ChildComponent,
        children: [
           path: 'grandchild',
           component: GrandchildComponent
        ]
      }
    ]
  }
]

I have a single router outlet defined in app.component.html.

When I navigate to the 'parent/child' route, this setup works fine, with the router outlet loading the ChildComponent.

However, when I navigate to the 'parent/child/grandchild' route, the GrandchildComponent doesn't load.

This does seem to work with a secondary router outlet in the child component, but is there any way that I could get the GrandchildComponent to load on the root router outlet, without the need for a secondary one?

4
  • What is the purpose of the nested routes if you have only one router outlet? Commented Nov 22, 2017 at 14:46
  • You would have to define the route at the top level. [{path: 'parent/child/grandchild', component: GrandchildComponent}], but as others have said it is not really a grandchild at this point so it is probably mislabeled. Commented Nov 22, 2017 at 14:51
  • @DeborahK The purpose is to use loadChildren to lazy load modules. Commented Nov 22, 2017 at 15:00
  • At the child level? Then what about the purpose of the grandchildren? Commented Nov 22, 2017 at 15:42

1 Answer 1

1

I would say no.

If you want to load the grandchild in the root outlet, then it's not a grandchild, it's a grandparent ! When you have nested routes, you need to have nested outlets.

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.