Class NavigationApi
This class wraps the browser's Navigation and History APIs, allowing server-side code to control page navigation, manipulate browser history, and perform redirects.
All methods are provided in two forms:
- Convenience form - No page parameter; uses thread-local page lookup
- Efficient form - Accepts page parameter; avoids thread-local lookup
Usage:
// Navigate to a URL
NavigationApi.navigateTo("/home");
// Navigate back in history
NavigationApi.back();
// Push a new history state
NavigationApi.pushState("New Page", "/new-url");
// Efficient form when page reference is available
NavigationApi.navigateTo(this, "/home");
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidback()Navigates back one page in the browser history using the current page context.static voidback(int pages) Navigates back the specified number of pages in the browser history using the current page context.static voidNavigates back one page in the browser history.static voidNavigates back the specified number of pages in the browser history.static voidbackAfterDelay(long delayMs) Navigates back in the browser history after a delay using the current page context.static voidbackAfterDelay(HtmlPage page, long delayMs) Navigates back in the browser history after a delay.static voidforward()Navigates forward one page in the browser history using the current page context.static voidforward(int pages) Navigates forward the specified number of pages in the browser history using the current page context.static voidNavigates forward one page in the browser history.static voidNavigates forward the specified number of pages in the browser history.static voidgo(int delta) Navigates the browser history by the specified delta using the current page context.static voidNavigates the browser history by the specified delta.static voidnavigateTo(HtmlPage page, String url) Navigates to the specified URL.static voidnavigateTo(String url) Navigates to the specified URL using the current page context.static voidnavigateToAfterDelay(HtmlPage page, String url, long delayMs) Navigates to the specified URL after a delay.static voidnavigateToAfterDelay(String url, long delayMs) Navigates to the specified URL after a delay using the current page context.static voidNavigates to the previous page in the browser history using the current page context.static voidNavigates to the previous page in the browser history.static voidNavigates to the referring page using the current page context.static voidnavigateToReferrer(HtmlPage page) Navigates to the referring page.static voidPushes a new state onto the browser history stack.static voidPushes a new state onto the browser history stack using the current page context.static voidreload()Reloads the current page using the current page context.static voidReloads the current page.static voidreloadAfterDelay(long delayMs) Reloads the page after a delay using the current page context.static voidreloadAfterDelay(HtmlPage page, long delayMs) Reloads the page after a delay.static voidNavigates to the specified URL without adding a history entry.static voidNavigates to the specified URL without adding a history entry using the current page context.static voidreplaceState(HtmlPage page, String title, String url) Replaces the current state in the browser history.static voidreplaceState(String title, String url) Replaces the current state in the browser history using the current page context.static voidSets the URL hash (fragment identifier).static voidSets the URL hash (fragment identifier) using the current page context.
-
Constructor Details
-
NavigationApi
public NavigationApi()
-
-
Method Details
-
back
public static void back()Navigates back one page in the browser history using the current page context. -
back
Navigates back one page in the browser history.- Parameters:
page- The page initiating the navigation.
-
back
public static void back(int pages) Navigates back the specified number of pages in the browser history using the current page context.- Parameters:
pages- The number of pages to navigate back.
-
back
Navigates back the specified number of pages in the browser history.- Parameters:
page- The page initiating the navigation.pages- The number of pages to navigate back.
-
forward
public static void forward()Navigates forward one page in the browser history using the current page context. -
forward
Navigates forward one page in the browser history.- Parameters:
page- The page initiating the navigation.
-
forward
public static void forward(int pages) Navigates forward the specified number of pages in the browser history using the current page context.- Parameters:
pages- The number of pages to navigate forward.
-
forward
Navigates forward the specified number of pages in the browser history.- Parameters:
page- The page initiating the navigation.pages- The number of pages to navigate forward.
-
reload
public static void reload()Reloads the current page using the current page context. -
reload
Reloads the current page.- Parameters:
page- The page to reload.
-
reloadAfterDelay
public static void reloadAfterDelay(long delayMs) Reloads the page after a delay using the current page context.- Parameters:
delayMs- The delay in milliseconds before reloading.
-
reloadAfterDelay
Reloads the page after a delay.- Parameters:
page- The page to reload.delayMs- The delay in milliseconds before reloading.
-
backAfterDelay
public static void backAfterDelay(long delayMs) Navigates back in the browser history after a delay using the current page context.- Parameters:
delayMs- The delay in milliseconds before navigating back.
-
backAfterDelay
Navigates back in the browser history after a delay.- Parameters:
page- The page initiating the navigation.delayMs- The delay in milliseconds before navigating back.
-
pushState
Pushes a new state onto the browser history stack using the current page context.- Parameters:
title- The title for the new history entry.url- The URL for the new history entry.
-
pushState
Pushes a new state onto the browser history stack.- Parameters:
page- The page initiating the history change.title- The title for the new history entry.url- The URL for the new history entry.
-
replaceState
Replaces the current state in the browser history using the current page context.- Parameters:
title- The title for the history entry.url- The URL for the history entry.
-
replaceState
Replaces the current state in the browser history.- Parameters:
page- The page initiating the history change.title- The title for the history entry.url- The URL for the history entry.
-
go
public static void go(int delta) Navigates the browser history by the specified delta using the current page context.Positive values navigate forward, negative values navigate back.
- Parameters:
delta- The number of history entries to traverse (positive = forward, negative = back).
-
go
Navigates the browser history by the specified delta.Positive values navigate forward, negative values navigate back.
- Parameters:
page- The page initiating the navigation.delta- The number of history entries to traverse (positive = forward, negative = back).
-
setHash
Sets the URL hash (fragment identifier) using the current page context.This is useful for SPA-style navigation without triggering a page reload.
- Parameters:
hash- The hash value to set (with or without the leading '#').
-
setHash
Sets the URL hash (fragment identifier).This is useful for SPA-style navigation without triggering a page reload.
- Parameters:
page- The page to set the hash on.hash- The hash value to set (with or without the leading '#').
-
replace
Navigates to the specified URL without adding a history entry using the current page context.Unlike
navigateTo(String), this method replaces the current history entry rather than creating a new one, so the user cannot navigate back to the current page.- Parameters:
url- The URL to navigate to.
-
replace
Navigates to the specified URL without adding a history entry.Unlike
navigateTo(HtmlPage, String), this method replaces the current history entry rather than creating a new one, so the user cannot navigate back to the current page.- Parameters:
page- The page initiating the navigation.url- The URL to navigate to.