Update application.yml to disable resource mapping for improved SPA handling
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.sshmanager.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* SPA 前端路由回退:未匹配到静态资源时返回 index.html,供 Vue Router history 模式使用。
|
||||
*/
|
||||
@Configuration
|
||||
public class SpaForwardConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**")
|
||||
.addResourceLocations("classpath:/static/")
|
||||
.resourceChain(true)
|
||||
.addResolver(new PathResourceResolver() {
|
||||
@Override
|
||||
protected Resource getResource(String path, Resource location) throws IOException {
|
||||
Resource resource = location.createRelative(path);
|
||||
if (resource.exists() && resource.isReadable()) {
|
||||
return resource;
|
||||
}
|
||||
return location.createRelative("index.html");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@ server:
|
||||
port: 48080
|
||||
|
||||
spring:
|
||||
web:
|
||||
resources:
|
||||
add-mappings: false # 使用 SpaForwardConfig 统一处理静态与 SPA 回退
|
||||
datasource:
|
||||
url: jdbc:h2:file:./data/sshmanager;DB_CLOSE_DELAY=-1
|
||||
driver-class-name: org.h2.Driver
|
||||
|
||||
Reference in New Issue
Block a user