0

I've created a dynamic file search URL that returns the file URL in the {row} form. And I've been trying to add the functionality to open the same file URL in a new tab on click.

Here {row} returns the full file path from the Device's directory which is, in my case, /users/prerak/Desktop/OpenMFRefer/data/message1

I've tried -

<Link to={`${row}`} target="_blank">{row}</Link>

But this redirects me to localhost:3000/<file path>. Instead, it should redirect me to file:///<file path>

I also tried - <Link to={`/${row}`} target="_blank">{row}</Link> which sends me to http://<file Path> which is pretty much more of the same issue.

Please tell me how I can fix this.

  • Opening file URLs directly is a [security risk](https://textslashplain.com/2019/10/09/navigating-to-file-urls/). Please see [this answer](https://stackoverflow.com/a/46480984/10538100) which describes how to setup a local server to serve specific files without needing the `file://` URL. – HudsonGraeme Jul 27 '22 at 00:31
  • try adding **//** before path or url i.e`to={'//${row}'}` to remove localhost from the url. – callmeizaz Jul 27 '22 at 03:36
  • Thanks for the Help and solutions. But the ```{'//${row}'}``` didn't work as It's still considered as a security concern. Is there any other workaround which I can implement without using any new packages? – Prerak Mathur Aug 01 '22 at 20:41

0 Answers0