0

I encountered a problem and couldn't solve it anywhere.

I need to configure spring boot URL mapping so that all URLs (http://localhost:xxx/*) is mapped to my index.html, with all the URL parameters included.

As you know react-router-dom changes the URL dynamically. But when you refresh it, the URL will not be found.

Thank you.

3
  • are you doing server side rendering or using something like tomcat to serve your server and client? Commented Oct 27, 2018 at 15:52
  • I'm using tomcat to serve the api, and the index.html containing react. Commented Oct 27, 2018 at 16:27
  • When you're viewing the "/" and change the URL to "/about" using react-router-dom, then hit refresh, the server is trying to find the "/about" URL that does not exist. Commented Oct 27, 2018 at 16:28

1 Answer 1

2

This is because you are using client side routing. When you go to /about, the server is looking for a static page in /about and can't find it. You need to config your tomcat war to point 404s to index.html and let react router handle router from there.

See this post:

404 returned on any URL accessed before accessing the home URL

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.