On my online art store I'm trying to achieve the following:
Result at this point: clicking the "Contact me" button on this page leads the visitor to "https://store.com/contact/smith-john/"
End result: clicking the "Contact me" button on the product page mentioned above leads the visitor to "https://store.com/contact/smith-john/?product=painting-1"
I've only found parts of the solution, any idea on how to achieve this?
Try this
const url = new URL("https://store.com/product/smith-john-painting-1/")
const artistUrl = url.origin
const parts = url.pathname.split("/")
const [lastName, firstName, item, number] = parts[2].split("-")
const pageUrl = `${artistUrl}/contact/${lastName}-${firstName}/?product=${item}-${number}`
console.log(pageUrl)