0

I have a route like this:

{
    path: 'parent',
    children: [
        {
            path: '',
            component: ParentComponent
        },
        {
            path: 'child1',
            children: [
                {
                    path: ':childID',
                    component: Child1Component
                }
            ]
        },
        {
            path: 'child2',
            children: [
                {
                    path: ':childID',
                    component: Child2Component
                }
            ]
        }
    ]
}

Now I want to call route for child1/childID. How do I route to it?

Right now I use this:

this._router.navigate(["child1", auction_ID]);

but it does not routes back to parent

2
  • "but it does not routes back to parent" If you want to go from child to parent, you should do something like this: this._router.navigate(["/parent"]): Commented Jun 22, 2017 at 0:06
  • If you want to navigate to the child route you'll need to `navigate(["parent", "child1", auction_ID]) Commented Jun 22, 2017 at 0:22

1 Answer 1

1

You have to start at the "top" when you are navigating to a certain route. In your case, you want to go to parent -> child1 -> :childID so you have to pass all those parts in the navigate method.

Navigate to the Child

this._router.navigate(['parent', 'child1', auction_ID]);

Navigate to the Parent

this._router.navigate(['parent']);
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.