[Used Gatsby framework] These days I tried adding a button which trigger the download of a zip file, and found that you can approach it as follows:
- Make sure your Button component root element is an
Link <a>
element, and have thelink
anddownload
component settings (the gear icon while having a button component selected) - In the code, Add the file you want to be downloaded on
static
folder:
◦ I added it onstatic/downloads
◦ This can be done later, but for context makes sense to be here - In plasmic UI, set the path for both link and download properties as follow:
/downloads/file_name.format
Notes:
• make sure after pushing the update to github, to add the file to that path.
• make sure Gatsby doesn’t add a /
slash symbol at the end of url. This can be done by adding trailingSlash: "ignore",
in the gatsby-config.ts file
I think this works only with custom hosting (vercel in my case), and only on the deployed version. (doesn’t work on localhost)