Skip to main content

useNavigationType

Returns the current navigation action which describes how the router came to the current location, either by a pop, push, or replace on the history stack.

Return Value

"POP" | "PUSH" | "REPLACE"
The current navigation type:
  • "POP" - The user navigated using the browser back/forward buttons
  • "PUSH" - A new entry was added to the history stack (e.g., via a link click or navigate())
  • "REPLACE" - The current entry in the history stack was replaced (e.g., via navigate("/path", { replace: true }))

Type Declaration

Usage Examples

Track Navigation Method

Conditional Behavior Based on Navigation Type

Differentiate Fresh Navigation from History Navigation

Common Patterns

Combining with useLocation

Notes

  • The navigation type is derived from the browser’s history API
  • This hook must be used within a <Router> component
  • The navigation type is available in all React Router modes (Declarative, Data, and Framework)
  • Initial page loads typically have a navigation type of "POP"
  • useLocation - Get the current location
  • useNavigate - Navigate programmatically
  • Link - Declarative navigation (creates PUSH navigations by default)