Reroute to original navigation target after login

Hi

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.

thanks
Jenny

Hi Jenny,

Have you checked [getNavigationTarget()]
(https://vaadin.com/api/platform/12.0.3/com/vaadin/flow/router/BeforeEvent.html#getNavigationTarget--) of the BeforeEnterEvent? Alternatively you could use getLocation().getPath().

As registered user you can view the training video about routing here: https://vaadin.com/training/course/view/v10-router 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.

thanks
Jenny

Hi Jenny

Our trainings are divided into different categories, see

https://vaadin.com/training/courses?type=all

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

The rest need a subscription.

Perhaps it is problem with direct link.