Linking and Navigating
Learn how navigation works in Bini.js and how to use the Link component and useNavigate hook.
Bini.js provides built-in navigation components and hooks that enable fast, client-side transitions between routes without full page reloads.
Link Component
The <Link> component is the primary way to navigate between routes. It's auto-imported in all pages and layouts, so you can use it without any import statements.
Link Props
| Prop | Type | Description |
|---|---|---|
| to | string | The destination route path |
| replace | boolean | Replace the current entry in history instead of adding |
| state | any | State to persist to the location |
| className | string | CSS class for styling |
| children | ReactNode | The content inside the link |
useParams Hook
The useParams hook returns an object of key/value pairs of the dynamic route parameters from the current URL.
useLocation Hook
The useLocation hook returns the current location object. Useful for accessing the current pathname, search params, and state.
useSearchParams Hook
The useSearchParams hook reads and updates the query string. It returns a URLSearchParams object and a setter function.
Best Practices
- Use
<Link>for standard navigation links - Use
<NavLink>for navigation menus that need active state styling - Use
useNavigatefor programmatic navigation (form submissions, redirects) - Use
useParamsto access dynamic route parameters - Use
useSearchParamsfor managing query strings and filters - All navigation hooks and components are auto-imported — no need to write import statements