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

后端 未结 8 1564
时光取名叫无心
时光取名叫无心 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:37

    In my case I wanted a simple solution as with creating a customer error page. However that solution still sets a status code 404 which is not desired.

    So I use a small jsp file which will set status code to 200 before outputting the SPA's index.html.

    I hope this helps someone else looking for a simple solution without returning status 404.

    web.xml

    
        404
        /spa.jsp
    
    

    spa.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%
        response.setStatus(200);
    %><%@include file="./dashboard/index.html"%>
    

提交回复
热议问题