如何使用 vaadin 路由器提供静态 html 文件
How the serve static html files with vaadin router
我的 hilla 应用程序中有以下路线配置
router.setRoutes([
{path: '/', component: 'home-view'},
]);
这是可行的,但我需要发布一些静态 html 文件。不确定将文件放在哪里以及如何配置路由器以使用 URL 访问它们,例如 /myfile.html
?
已经尝试将它们放入 /frontend
文件夹并添加路由,但不起作用,但创建了一个循环
{
path: '(.*)\.html',
action: (ctx, commands) => {
window.location.pathname = ctx.pathname;
}
}
在这里找到How do I deliver static html pages with vaadin router (client side)?
该服务器是 Spring 引导服务器,因此您放入 src/main/resources/META-INF/resources
中的任何文件都可用,例如如果你创建 src/main/resources/META-INF/resources/myfile.html
那么你可以访问它 http://localhost:8080/myfile.html.
如果您只是加载静态 HTML 页面,则无需为其配置路由器。对于 link 你可以添加 router-ignore
这样路由器就不会试图拦截它,例如`"
我的 hilla 应用程序中有以下路线配置
router.setRoutes([
{path: '/', component: 'home-view'},
]);
这是可行的,但我需要发布一些静态 html 文件。不确定将文件放在哪里以及如何配置路由器以使用 URL 访问它们,例如 /myfile.html
?
已经尝试将它们放入 /frontend
文件夹并添加路由,但不起作用,但创建了一个循环
{
path: '(.*)\.html',
action: (ctx, commands) => {
window.location.pathname = ctx.pathname;
}
}
在这里找到How do I deliver static html pages with vaadin router (client side)?
该服务器是 Spring 引导服务器,因此您放入 src/main/resources/META-INF/resources
中的任何文件都可用,例如如果你创建 src/main/resources/META-INF/resources/myfile.html
那么你可以访问它 http://localhost:8080/myfile.html.
如果您只是加载静态 HTML 页面,则无需为其配置路由器。对于 link 你可以添加 router-ignore
这样路由器就不会试图拦截它,例如`"