Using a BeforeEnterObserver, the event can be used to forward to a specific page. In my case I can’t use the BeforeEnterObserver, but would like to get the same functionality. Using UI.navigate does not seem to work, even though I have verified I get a UI object and the navigate call is made. Are there any suggestions how I can get this functionality?
It depends why you can’t use the observer. Are you in a background thread? Something else?
I am trying to make a base class for a set of pages that will check a user for a specific role, and if the user does not have that role redirect them to the main view of the application. I want to leave the AfterNavigation, BeforeEnter and BeforeLeave observers for use by the child views.
I’ve created exactly something like this in the past.
My base class implements the observer and creates an abstract or empty method beforeYourName which can be overwriten by the extending classes. The default observer does all the required access checks inside the base class and delegates to the beforeYourName if the user is authorized
Another option could be beforeenterlistener (and similar) instead of observers
Thanks for the suggestions, I appreciate it
The BeforeEnterEvent is happening in middle of the navigation lifecycle, for sake of consistency new UI.navigate cannot be triggered in the middle of existing navigation cycle. Thus BeforeEnterEvent#forwardTo(..) and BeforeEnterEvent#rerouteTo(..) methods should be used instead. There are several overloads of these.