I am doing a Vaadin App that has three Views, and whenever the users enters an unknown URL he sees this page:
Could not navigate to 'stackoverflow' Reason: Couldn't find route for 'stackoverflow'
Available routes: app login logout
This detailed message is only shown when running in development mode. I want to define a route instead of showing this page, how to do it? Like whenever this messgage is shown it should just swallow it and redirect to an existing route.
CodePudding user response:
What you're seeing is the default "not found" error handler. You can define your own error handler by creating a component that implements HasErrorParameter<NotFoundException>
. Flow will automatically that class from the application in the same way that it picks up @Route
annotated classes.
CodePudding user response:
I managed to do it this way:
@Tag(Tag.DIV)
@DefaultErrorHandler
public class MYNoRouteHandler extends RouteNotFoundError {
private static final long serialVersionUID = 7169334501543395112L;
private static final Logger log = LoggerFactory.getLogger(MyNoRouteHandler.class);
@Override
public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) {
log.debug("Not existing view requested with name: /" event.getLocation().getPath());
log.debug("Redirect user to /start");
event.forwardTo(StartView.class);
return HttpServletResponse.SC_NOT_FOUND;
}
}
Thanks one more time for helping me out. Sometimes i wonder why others did not ask. Maybe they read the manual?