Stackflow
A stack-based navigation flow component for managing sequential views with animations
Installation
Terminal
Import
Component.tsx
Basic
Stackflow is a **non-linear stack navigation** component for managing multi-page views.
### Core Concepts
- **Stackflow**: Container component, manages navigation state
- **Stackflow.Item**: Page component, each `id` corresponds to one page
- **Stackflow.Prefix**: Fixed header area, does not scroll with pages
- **Stackflow.Suffix**: Fixed footer area, does not scroll with pages
- **useStackflowContext**: Hook to access navigation methods and state
### Navigation Methods
- `push(id)`: Navigate to a specified page and record in history
- `back()`: Return to the previous page
- `canGoBack`: Whether there is a previous page to return to
- `current`: Current page information
Use Stackflow Context
`useStackflowContext` is a hook that provides access to the navigation state and methods.
### Return Values
| Property | Type | Description |
|----------|------|-------------|
| `push` | `(id: string) => void` | Navigate to a page by id |
| `back` | `() => void` | Go back to the previous page |
| `clearHistory` | `() => void` | Clear history and return to the first page |
| `canGoBack` | `boolean` | Whether there's a previous page |
| `current` | `{ id, content } \| undefined` | Current page info |
| `history` | `string[]` | Array of visited page ids |
| `direction` | `"forward" \| "backward"` | Current navigation direction |
| `isInitial` | `boolean` | Whether it's the initial render |
### Usage
```tsx
const { push, back, canGoBack, current, history, direction, isInitial, clearHistory } = useStackflowContext()
```
current?.id:
undefined
canGoBack:
false
direction:
forward
isInitial:
true
history: ["step1"]