0

I manage to setup react, basically express just as the api server. I can navigate around my react app using react-router, it's a single page application.

But when I refresh for example http://localhost/login I got error of cannot GET /login I know the issue, but I don't know how to fix it.

0

1 Answer 1

3

You haven't posted your code, but I guess that you don't return the React app at the * route, which means that if you start at /, you'll be fine because it's handled, but if you want to get any other endpoint not via the app itself, but directly via an address, Express will look for a /login (for example) route handler and hence it's not there, it'll return 404.

TLDR: send the React SPA as the response on * GET and React Router will handle the rest.

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

Comments

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.