【发布时间】:2020-06-12 15:28:24
【问题描述】:
这是非常标准的 Spring SPA 控制器。
@Controller
public class SPAController {
@GetMapping("/")
public String home() {
return "forward:/static/index.html";
}
@GetMapping("/**/{[path:[^\\.]*}")
public String html5Mode() {
return "forward:/static/index.html";
}
}
如何在 Micronaut 中做同样的事情?已经有一些关于 SO 的答案,比如这个:
@Get("/{[path:[^\\.]*}")
@Secured(SecurityRule.IS_ANONYMOUS)
@Produces(MediaType.TEXT_HTML)
public HttpResponse<?> refresh(HttpRequest<?> request) {
StreamedFile indexFile = new StreamedFile(res.getResource("classpath:public/index.html").get());
return HttpResponse.ok(indexFile);
}
这是完全错误的。我“不知道”index.html 文件位置,我只知道它的 URL。
【问题讨论】:
-
什么情况下不知道索引文件在哪里?