0

i am passing two parameter with route but its not working. when i click on routerLink it is redirecting me to my default route.
means there is no route who is accepting parameters.
What am i missing..?
THANKS in Advance.

paht is:

{path:'Buy/:term1/:term2', component: Buycomponent}

and i am passing parameters like this:

<a [routerLink] ="['/Buy',{term1:'sale',term2:'home'}]">data</a>

in component i am getting parameters like this:

this.route.params.subscribe(response => console.log(response.term1 , responce.term2));  

.
Updated...

for single value it is working fine.

{path:'Buy/:term1, component: Buycomponent}

and passing parameter like this:

<a [routerLink] ="['/Buy','sale']">data</a>

in component i am getting parameters like this:

this.route.params.subscribe(response => console.log(response.term1));
8
  • 1
    You could access the route like <a [routerLink] ="/Buy/sale/home">data</a> Commented Dec 12, 2018 at 15:34
  • 1
    The way you are doing, it is called query parameters. What you want do is route parameters. Which, people have already answered Commented Dec 12, 2018 at 15:46
  • @IvanS95 thanks for answer but its not working for me Commented Dec 14, 2018 at 6:52
  • @SumeetKale did you find any thing wrong in my code..? Commented Dec 14, 2018 at 6:53
  • 1
    @IvanS95 That doesn't work. You either bind to an expression or use a string value, not both. Commented Dec 14, 2018 at 7:19

2 Answers 2

1

Try this:

<a [routerLink] ="['/Buy','sale','home']">data</a>

Use this syntax when you want to pass optional parameters

<a [routerLink] ="['/Buy',{term1:'sale',term2:'home'}]">data</a>
Sign up to request clarification or add additional context in comments.

1 Comment

it works after some tries i don't know why it was not working on first try..anyway its working thanks
0

You can use

<a [routerLink] ="['/Buy','sale','home']">data</a>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.