1

How can I use number 2 here in this url ( http://localhost:3001/products/2) in axios request ...

 const getProd = () => { axios.get(`http://localhost:3000/customer/product/${I want to take the number from the url and use it here}`) .then((result) => { setProducts(result.data); return }) } 
2
  • Does this answer your question? How to get the value from the GET parameters? Commented Dec 29, 2020 at 11:00
  • You could create a regex or some other utility specific to that route/URL. Are you using any routing/navigation in your app? You may be able to leverage something from that. Commented Dec 29, 2020 at 11:03

1 Answer 1

1

Try this

window.location.href.split('').pop(); 

if URL has an id more than 1 digit(eg. - 1212)

window.location.href.split('/').pop(); 
Sign up to request clarification or add additional context in comments.

1 Comment

I think it should be split('/')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.