Search code examples
hillavaadin-router

How the serve static html files with vaadin router


I have te following route configuration in my hilla app

router.setRoutes([
  {path: '/', component: 'home-view'},
]);

this is works, but I need to publish some static html files. Not sure where to put the files and how to configure router to make them accessible with URL like /myfile.html?

already tried to put them in /frontend folder and add route, but does not work but creates a loop

{
  path: '(.*)\.html',
  action: (ctx, commands) => {
      window.location.pathname = ctx.pathname;
  }
}

Found it here How do I deliver static html pages with vaadin router (client side)?


Solution

  • The server is a Spring Boot server so any file you put inside src/main/resources/META-INF/resources is made available, e.g. if you create src/main/resources/META-INF/resources/myfile.html then you can access it as http://localhost:8080/myfile.html.

    If you are just loading a static HTML page there is no need to configure the router for it. For a link you can add router-ignore so that router will not try to intercept it, e.g. `"