在 Vert.x Web 路由器上的不存在路由上提供静态 webroot/index.html 数据

Serve static webroot/index.html data on non-existing routes on Vert.x Web Router

场景:

路由器代码:

Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());

router.route("/api/login/account").handler((RoutingContext ctx) -> {
  // Handler is here
});
router.route("/api/currentUser").handler(ctx -> {
  // Handler is here
});
router.route().handler(StaticHandler.create());
router.route("/*").hanler(StaticHandler.create("webroot/index.html"));

文件夹 webroot 有以下文件:

问题:

我哪里漏了这里?解决方案是什么?

您应该添加最后一个处理程序,在一切都失败时发送您想要的文件。例如:

ctx.response().sendFile('webroot/index.html');

不要忘记添加您可能需要的 headers,例如缓存指令、位置、内容类型...