0

This is my custom PageNotFound route:

@ParentLayout(MainLayout.class)
@AnonymousAllowed
public class PageNotFound extends RouteNotFoundError {

    @Override
    public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) {
        VerticalLayout verticalLayout = new VerticalLayout();

        // some logic

        getElement().insertChild(0, verticalLayout.getElement());

        return HttpServletResponse.SC_NOT_FOUND;
    }

}

Despite the fact I return HttpServletResponse.SC_NOT_FOUND the page still returns 200ok instead of 404. What am I doing wrong and how to fix it?

alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • Known limitation. https://github.com/vaadin/flow/issues/13421 – Knoobie Jan 10 '23 at 21:34
  • Thanks, is it safe to use `vaadin.eagerServerLoad=true` as a workaround for this issue with Vaadin Flow 23 ? – alexanoid Jan 10 '23 at 21:44
  • I would not recommend it personally. – Knoobie Jan 11 '23 at 05:54
  • Are there any other ways to return the correct code? The problem - to improve the SEO of my Vaadin Flow application, I connected prerender.io. Without the correct 404 code, prerender.io will render and cache tons of the false-present pages... – alexanoid Jan 11 '23 at 10:08
  • Handle it before the request hits Vaadin, for example in Spring Boot. – Knoobie Jan 11 '23 at 11:30

0 Answers0