smolter
API

useNavigationType

Read whether the current application history entry came from POP, PUSH, or REPLACE.

Compatibility

ReactAvailable in this renderer's browser integration.
React SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.
PreactAvailable in this renderer's browser integration.
Preact SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.

Import from @kasperrt/smolter/react @kasperrt/smolter/preact

Signature

function useNavigationType(): NavigationType;

Parameters

Takes no arguments and requires RouterProvider. The browser navigation integration installed by mountApplication maintains the value.

Returns

Returns the NavigationType string POP, PUSH, or REPLACE. The initial value is POP. This describes history behavior, not whether a loader or action is currently pending.

Example

Read the navigation type where the UI needs to distinguish a replacement from a new history entry.

import { useNavigationType } from "@kasperrt/smolter/preact";

export function HistoryStatus() {
  const type = useNavigationType();

  return <span>History action: {type}</span>;
}

Commit timing

History state is published when the navigation integration sees an idle snapshot. With a retained view this can follow the underlying request completion. A standalone RouterProvider without that integration keeps the store’s initial value.

View implementation ↗