1

I am using angular 6 and trying to import a component as child component.

I have a component which can be accessed by routing to '/register' which loads signUpComponent and and I have other component which loads ServicesComponent using '/services' and also I am using both the routes in multiple components.

Now my problem is that I want to load ServicesComponent as child component of SigUpComponent i.e. something like this '/register/services' (kind of nested routing) with condition that my both routes are defined separately. Is there any way to do it, instead of redefining a third route as '/register/services' with ServicesComponent defined as child component of SigUpComponent

2

1 Answer 1

2

You can use children routing like this ::

const parentModuleRoutes: Routes = [
    {
        path: 'parent-component',            //<---- parent component declared here
        component: PetParentComponent,
        children: [                          //<---- child components declared here
            {
                path:'child-one',
                component: ChildOneComponent
            },
            {
                path:'child-two',
                component: ChildTwoComponent
            },
            {
                path:'child-three',
                component: ChildThreeComponent
            },
            {
                path:'child-four',
                component: ChildFourComponent
            },
        ]
    }
];

You can use this links for more informations ::

https://angular.io/guide/router#child-routing-component(As per @wannadream says)

https://itnext.io/child-routes-with-respective-components-in-angular-4-36f1be42278e

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.