react routing is able to handle different url path but tomcat returns 404 not available resources

后端 未结 8 1578
时光取名叫无心
时光取名叫无心 2020-12-07 15:01

I am new in reactjs and I have a little project in reactjs to play with and learn it. I need to have to type of headers which will be shown based o

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 15:46

    My solution is like a workaround for JSP engines (e.g. Tomcat), but it works great with minimal code.

    I created an "index.jsp" parallel to "index.html" (in the content root folder) with following code:

    index.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@include file="index.html"%>
    

    I configured all urls to redirect to this JSP in web.xml

    web.xml

    
        index
        index.jsp
    
    
        index
        /*
    
    

    Now any URL requested to Tomcat will internally get redirected to index.jsp that is effectively index.html. Once react-router loads in browser, it takes care of rendering the right component and subsequent requests.

提交回复
热议问题