hc-oss/react-web-share

Encoded URI while using `navigator.share`

sudhanshug16 opened this issue · 2 comments

Hey, firstly thanks for the amazing package.

I noticed that the url that I pass to the component via data prop is actually URL encoded.
https://github.com/harshzalavadiya/react-web-share/blob/0b3d5ef70c6719e1f7982f88435a14143a6af8af/src/index.tsx#L18 this is the code responsible for the same.

Correct me if I am wrong, there shouldn't be a need to encode the url here. And in fact the package should assume that the URL provided by the user is correct. If not, then it is user's fault.

For example:

I passed this

url: `${window.location.origin}/view`

and the URI for the navigator.share came out in this format

<current_pathname>/encoded(<origin>/view)

image

@sudhanshu16 that's a great question, by default I opted for encoding URL because it will skip after second query param if passed decoded notice x=y in URL but missing in tweet

Hmm. That is probably fine for twitter, but that is not required for the native share option. I forked the repository and removed the uri enoder. It worked for my use case (I dont have any query params).

As for the solution to this, it seems you can pass the data.url to shareData.url as sent by the user and then encode it in the social share icon components.

Anyways, I've opened a PR for the same. Do take a look. That should solve the problem