通配符*
已绑定到ResourceHttpRequestHandler
,最好保留它:
Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
如果您需要更多管理(例如服务器端渲染),您可以定义自己的ErrorController
.
所以当 spring router 什么都不匹配时,spring 可以响应你的 react ssr 结果:
@Controller
public class ServerSideRenderrer implements ErrorController {
@Override
public String getErrorPath() {
return "/error";
}
@RequestMapping(value = "/error")
@ResponseBody
public String error(HttpServletRequest request, HttpServletResponse response) {
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
String original = request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
String method = request.getMethod();
if (statusCode == 404 && method.equalsIgnoreCase("GET") && original.contains("xxx")) {
response.setStatus(200);
return ssrHtmlContent;
}
return "Error handling";
}
}