ipegasus
ipegasus

Reputation: 15262

ReactJS Static File

I would like to know how to serve txt files like robots.txt and verify.txt in a ReactJS app?

Eg: http://localhost:3000/.well-known/apple-developer-merchantid-domain-association.txt

So far I have tried adding the files to the public folder, but the app does not recognize the URL.

Thanks in advance

ReactJS App

Upvotes: 3

Views: 5028

Answers (1)

ipegasus
ipegasus

Reputation: 15262

The following solution works for serving a static file via React JS React Router.

  1. Add the file to the public folder
  2. Include a route that points to the static file in the public folder Eg: /robots.txt:

Solution via React Router

const reload = () => window.location.reload();

<Route path="/my-static-file.ext" onEnter={reload} />

Upvotes: 8

Related Questions