Skip to content

Navigation History Component

The NavigationHistoryComponent manages navigation stack and allows programmatic navigation control.

Basic Info

Description

This component provides access to navigation history, enabling go-back, go-forward, and stack inspection functionality.

How to Use

1. Web Implementation

javascript
import { useNavigationHistory } from '@bagisto-native/react';

const NavigationControls = () => {
    const { canGoBack, canGoForward, goBack, goForward, getHistory } = useNavigationHistory();

    const handleBack = () => {
        if (canGoBack()) {
            goBack();
        }
    };

    const handleHistoryCheck = async () => {
        const history = await getHistory();
        console.log("Navigation history:", history);
    };

    return (
        <div>
            <button onClick={handleBack} disabled={!canGoBack()}>
                Back
            </button>
            <button onClick={goForward} disabled={!canGoForward()}>
                Forward
            </button>
            <button onClick={handleHistoryCheck}>
                View History
            </button>
        </div>
    );
};

2. Native Side

kotlin
navigator.registerBridgeComponent("navigationHistory", NavigationHistoryComponent(this))

API Reference

PropertyTypeRequiredDescription
canGoBack()FunctionNoCheck if back navigation possible
canGoForward()FunctionNoCheck if forward navigation possible
goBack()FunctionNoNavigate back in stack
goForward()FunctionNoNavigate forward in stack
getHistory()FunctionNoGet full navigation history

The component also emits events for navigation state changes:

javascript
import { useEffect } from 'react';
import { useEventListener } from '@bagisto-native/react';

const NavigationListener = () => {
    useEventListener('navigationChanged', (event) => {
        console.log("Navigation changed:", event.detail);
        // Handle navigation state change
    });

    return null;
};

Use Cases

  • Custom navigation buttons
  • Swipe-back gesture handling
  • Deep link interception
  • Navigation state persistence

Next Steps

Released under the MIT License.