how can i do angular routing to child to component

Viewed 25

i am trying to navigate to my child defined component but my router is not recognizing the given route.

route is like as follow :

in Router file i have defined something like this:

const routes: Routes = [
{
    path: "",
    redirectTo: "products",
    component: StandardproductsComponent,
    pathMatch: "full",
    canActivate: [AuthorizedGuardService],
},
{
    path: "products",
    component: StandardproductsComponent,
    resolve: {
        loaded: StandardsResolver
    },
    children: [ 
        {
            path: ":productId/types",
            component: StandardtypesComponent,
            // resolve: {
            //     loaded: StandardTypesResolver
            // },
            // canActivate: [AuthorizedGuardService]
        }
    ]
}];

i won't able to do so like this way can anyone help me with this how can make my route workable. i want to have route like this : v3/products/{productId}/types

1 Answers

You have 2 routes that points to the same name & same component

try doing the following

const routes: Routes = [
    {
        path: "",
        redirectTo: "products",
        pathMatch: 'full'
    },
    {
        path: "products",
        component: StandardproductsComponent,
        resolve: {
            loaded: StandardsResolver
        },
        children: [
            {
                path: ":productId/types",
                component: StandardtypesComponent,
            }
        ]
    }
];

and of course that StandardproductsComponent must have

<router-outlet></<router-outlet>

Hope this helps!

Related