Get actual path isn't possible?

Hello,

I am trying to apply a different css depending on the url of the user. For that I need to know the path when the page initializes.

But apparently there is no getPath () method. In addition, the getUi () method is null when initializing the page. Should I miss something? If not, is it possible to do this differently with vaadin?

Thanx you for your futur responses.

Hello Guillaume,

you can get the path when the page initializes this way

        String path = UI.getCurrent().getRouter().getUrl(UserView.class);

Note that getUI().get() will give you an error if you call it in the constructor because the component is not still initialized.

In the case that you need to call getUI().get(), you can call it implementing navigation observers:

public class YourClass extends VerticalLayout implements AfterNavigationObserver {

	@Override
	public void afterNavigation(AfterNavigationEvent event) {
		String path = getUI().get().getRouter().getUrl(UserView.class);
	}
}