NavigationStore.forward()method
Navigate forward to a URL, pushing a new browser history entry.
forward(possible: PossibleURL): void
new NavigationStore(url: PossibleURL = typeof window === "undefined" ? "/" : window.location.href, base?: PossibleURL)
| Param | Type | |
|---|---|---|
url | PossibleURL | The initial URL (defaults to the browser's window.location.href, or "/" when there is no window, e.g. during server rendering). Defaults to typeof window === "undefined" ? "/" : window.location.href |
base | PossibleURL | Optional base URL that relative navigations resolve against. |
| Return | |
|---|---|
NavigationStore | Store holding the current navigation URL and driving browser history. |
Store holding the current navigation URL and driving browser history.
URLStore; the current location is its value.forward() pushes a new history entry; redirect() replaces the current one.The store holding the current navigation URL and driving browser history. It extends URLStore — the current location is its value — and is owned by <Navigation>. Reach for it via requireNavigation() rather than constructing your own.
Things to know:
forward() pushes a new browser history entry; redirect() replaces the current one. Both resolve the destination against the store's base.shelving/store URLStore, so components can subscribe to it for re-renders.import { requireNavigation } from "shelving/ui";
function LogoutButton() {
const nav = requireNavigation();
return <Button onClick={() => nav.redirect("/login")}>Log out</Button>;
}Constructed directly only when wiring navigation by hand (e.g. tests):
import { NavigationStore } from "shelving/ui";
const nav = new NavigationStore("/");
nav.forward("/home");const nav = new NavigationStore("/"); nav.forward("/home");Navigate forward to a URL, pushing a new browser history entry.
forward(possible: PossibleURL): void
Redirect to a URL, replacing the current browser history entry.
redirect(possible: PossibleURL): void