Fix SPA 404 fallback: register ErrorPage /index.html for Vue Router

This commit is contained in:
2026-05-25 21:47:47 +08:00
parent b70d814b6d
commit 9342f14d65
@@ -1,12 +1,15 @@
package com.reportdist.config;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
public class WebConfig implements WebMvcConfigurer, ErrorPageRegistrar {
@Override
public void addCorsMappings(CorsRegistry registry) {
@@ -21,4 +24,9 @@ public class WebConfig implements WebMvcConfigurer {
registry.addResourceHandler("/uploads/**")
.addResourceLocations("file:./uploads/");
}
}
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
registry.addErrorPages(new ErrorPage("/index.html"));
}
}