Direct linking results in "URI is not hierarchical" exception

I am using Spring Boot 3.1.2 with Vaadin starter version 24.1.4.
I have a route for AdminEditTypeView of “/content” and implement HasUrlParameter. In my layout I have a RouterLink(“Edit type”, AdminEditTypeView.class, “article”). When I click it I come to /content/article which works. But when I reload or entering localhost:8080/content/article in browser I get the attached stacktrace
message.txt (7.25 KB)

The class in question
@Route(value = “/content”, layout = AdminLayout.class)
@PageTitle(“Edit content type”)
public class AdminEditTypeView extends VerticalLayout implements HasUrlParameter {
private String typeSlug;
private Div div;

public AdminEditTypeView() {
    div=new Div();
    add(div);
}

@Override
public void setParameter(BeforeEvent beforeEvent, String s) {
    if("article".equals(s)) {
        this.typeSlug = s;
        div.setText(s);
    } else {
        beforeEvent.rerouteToError(NotFoundException.class, "Type does not exist");
    }
}

}

I would recommend to use https://vaadin.com/docs/latest/routing/additional-guides/route-templates to ease usage and handling

I have tried that (and found it easy to use). Same error on direct linking.

Ahh

Now I see it - remove the / from the beginning

Same error. @Route(value = “content”, layout = AdminLayout.class)

@versatile-zorse do you happen to have another idea? This looks really strange

I have a feeling that the route is only “partially” registered and it’s kinda forgotten about once directly navigated to… because… looking at the stack trace the static file server trys to handle it

That’s weird… Do you happen to have a content directory in your project resources?

I don’t. I tried change “content” to something jibberish like “kaluxiflepp” (both with and without leading slash). Same thing. I debugged into flow-server.jar:com.vaadin.flow.server.StaticFileServer#resourceIsDirectory which gets parameter URL resource = “file:web/static/kaluxiflepp/article”.
So the question is why is StaticFileServer mapped to a Route.

Worth noting is that I’m running vaadin in development mode.

StaticFileServer is executed before evaluating routes

Your project is spring boot with embedded tomcat?

I’m running spring boot with embedded tomcat, yes. I found the culprit!
I set the property spring.web.resources.static-locations to file:web/static to be able to serve static content from filesystem. That somehow messed up vaadins routes. Setting vaadin url-mappings to something other than /* did not help.
Is this a bug in Vaadin or Spring Boot or something I misconfigured?

It seems like that with the config you set the servlet container returns an URL even for resources that do not exist. I will check tomorrow and get back to you

Nevertheless interesting find! Thanks for sharing :man_bowing:

Thanks for the investigation

What I’m ultimately after is to have the frontend (root) site served by “plain” spring boot and mvc using its template engines but using Vaadin for the admin. Preferably isolated to /admin. I’m building a CMS of sorts, some resources should be user provided and served both dynamically (via templates) and statically (images and possibly some CSS).

From experience with those kind of setups and the fear of scaling problems: try to separate both apps and add a third “Microservice” called “Backend” that has the API for both “frontends” allowing you to up/downscale as needed