Reroute to original navigation target after login


I’m using an implementation of VaadinServiceInitListener my application (v12.0.0) to check if the user is logged in before entering a view. If the user is not logged in I reroute to the LoginView. That works fine, however, after log in I would like to reroute back to the original navigation target. What is the best way to do this? The original navigation target is overwritten when I reroute to the Login view.

I could store the original navigationTarget class in the session though I sometimes get RouteNotFoundError as the navigation target in the BeforeEnterEvent. I’m not sure what is causing this, I don’t think I am trying to navigate to an undefined route.


Hi Jenny,

Have you checked [getNavigationTarget()]
( of the BeforeEnterEvent? Alternatively you could use getLocation().getPath().

As registered user you can view the training video about routing here: Check especially Exercise 4, which is actually giving you the solution.

Br. Tatu

Hi Tatu

I’ll check that out that video, thank you.

Yes, I’m getting the navigation target from the BeforeEnterEvent but once I reroute to the Login view the navigation target has already changed to the Login view so the original target has been lost and in order to store the original navigation target I need to check that it is not RouteNotFoundError.


Hi Jenny

Our trainings are divided into different categories, see

The ones under category “Free” should be accessible if you have registered & signed in

The rest need a subscription.

Perhaps it is problem with direct link.