Programmatically switch the current page in a multipage app.
When Jt.switchPage
is called, the current page execution stops and the specified page runs as if the
user clicked on it in the sidebar navigation. The specified page must be recognized by Jeamlit's multipage
architecture (your main app class or an app class in the available pages).
Method Signatures and Parameters | |
Jt.switchPage(Class<?> pageApp) | pageApp (Class<?>) The target page. If |
Examples
Conditional page switching with checkboxes
import io.jeamlit.core.Jt;
public class SwitchPageApp {
public static class WelcomePage {
public static void main(String[] args) {
Jt.title("Welcome Page").use();
Jt.text("Please complete the requirements below to proceed:").use();
boolean agreedToTerms = Jt.checkbox("I agree with Bob").use();
boolean confirmedAge = Jt.checkbox("I agree with Alice").use();
if (agreedToTerms && confirmedAge) {
Jt.text("All requirements met! Redirecting to dashboard...").use();
Jt.switchPage(DashboardPage.class);
} else {
Jt.text("Please check both boxes to continue.").use();
}
}
}
public static class DashboardPage {
public static void main(String[] args) {
Jt.title("Dashboard").use();
Jt.text("Welcome to your dashboard!").use();
Jt.text("You have successfully completed the requirements.").use();
}
}
public static void main(String[] args) {
Jt.navigation(Jt.page(WelcomePage.class).title("Welcome").icon("👋").home(),
Jt.page(DashboardPage.class).title("Dashboard").icon("📊"))
.hidden()
.use();
}
}
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.