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 
            })
    }
Alaa Khalila
  • 169
  • 1
  • 11
  • Does this answer your question? [How to get the value from the GET parameters?](https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters) – Álvaro Tihanyi Dec 29 '20 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. – Drew Reese Dec 29 '20 at 11:03

1 Answers1

1

Try this

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

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

window.location.href.split('/').pop();
akhtarvahid
  • 9,445
  • 2
  • 26
  • 29