How I can use React-Router to point directly to a route defined with Express on the backend instead of rendering a component? I want to return valid JSON with no HTML included in the response.
1 Answer
React-Router only handles routing on the React frontend.
There is no way for React-Router to point to an Express Route on the back end.
A React component would have to use that API endpoint.
Why not just hit the endpoint manually.
4 Comments
Forrest Wilkins
I need to be able to reach the route defined in Express without specifying a port number. Here's my other question regarding the issue I'm having stackoverflow.com/questions/61160329/…
Forrest Wilkins
I'm trying to implement an ActivityPub API for a social network built with the MERN stack. So when I search for the user created on my server in Mastodon, they need to receive a valid JSON response with no HTML in order for their server to be able to read it.
Forrest Wilkins
Is there any way to return a plaintext response with React, containing no HTML at all and only JSON?
Forrest Wilkins
Adding a rewrite in my nginx config is what solved my issue.