0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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/…
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.
Is there any way to return a plaintext response with React, containing no HTML at all and only JSON?
Adding a rewrite in my nginx config is what solved my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.