noshusan
noshusan

Reputation: 313

Redirect to root url In vaadin

i have a simple Vaadin login application.After user login the URL looks something like below

http://localhost:8080/app/#!loogedin

what i wanted to do is after logout the URL should look something like this

http://localhost:8080/app/

i have tried

Page.getCurrent().setUriFragment("", true);

but its not working

Upvotes: 1

Views: 5969

Answers (2)

min
min

Reputation: 1098

for vaadin 10, you may use this code instead

getUI().ifPresent(ui -> {
    ui.getPage().executeJavaScript("window.location.href = 'you url'");
});

reference https://vaadin.com/forum/thread/17069258

Upvotes: 0

SSH
SSH

Reputation: 1627

You can do the redirect using the setLocation() method in Page. This needs to be done before closing the session, as the UI or page are not available after that.

public class MyUI extends UI {
    @Override
    protected void init(VaadinRequest request) {
        setContent(new Button("Logout", event -> {// Java 8
            // Redirect this page immediately
            getPage().setLocation("/myapp/logout.html");

            // Close the session
            getSession().close();
        }));

        // Notice quickly if other UIs are closed
        setPollInterval(3000);
    }
}

To understand further have a look Closing a session

Upvotes: 3

Related Questions