mateclaw/mateclaw-server/src/main/java/vip/mate/config/SpaForwardController.java

27 lines
796 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package vip.mate.config;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
/**
* SPA 前端路由 Fallback
* <p>
* 将不含扩展名的 GET 请求转发到 index.html由 Vue Router 接管客户端路由。
* 路径段正则 {@code [^\\.]*} 排除含 "." 的路径(静态资源如 .js/.css/.ico
* 同时 Spring MVC 会优先匹配 @RestController 精确路由,因此不会影响 /api/** 接口。
*
* @author MateClaw Team
*/
@Controller
public class SpaForwardController {
@GetMapping(value = {
"/{path:[^\\.]*}",
"/{path1:[^\\.]*}/{path2:[^\\.]*}",
"/{path1:[^\\.]*}/{path2:[^\\.]*}/{path3:[^\\.]*}"
})
public String forward() {
return "forward:/index.html";
}
}