Manage navigation with NavigationHistory
mainPinecone Router maintains an independent NavigationHistory object that tracks path visits. This allows for back() and forward() operations without relying solely on the browser API.
History Logic:
- Duplicates: Visiting the same path twice does not add a new entry.
- Redirects: If a handler redirects, the original (redirected-from) path is not added to the history, preventing loops.
- Branching: If you navigate back and then click a new link, all entries after your current index are removed before the new path is appended.
API:
index: The current position in history.entries: Array of visited paths.canGoBack()/canGoForward(): Check if navigation is possible.back()/forward(): Move through history.to(index): Jump to a specific history position.
// Access via $history in Alpine or PineconeRouter.history in JS
if (history.canGoBack()) {
history.back();
}