2

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

2
  • Where does the v3 in your example route get defined? Commented Mar 9, 2020 at 15:34
  • where is you <router-outlet></router-outlet>? Commented Mar 9, 2020 at 15:54

1 Answer 1

2

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!

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

1 Comment

thanks but i missed that i should not make (standardtypescomponent) as child component as i dont want standardproductscomponent to be persist along with other component hence i am using regular routing instead of child routing.

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.