DocsPluginsShowcaseReleases
npmStar us on GitHub

Getting Started

IntroductionInstallationProject StructureLayouts and PagesLinking and Navigating

Routing

Folder-Based RoutingFile-Based RoutingDynamic RoutesParallel RoutesIntercepting RoutesCatch-All RoutesMDX & Markdown Pages

Special Files

Loading UIError BoundariesTemplateDefaultNot Found

Data Fetching

LoadersActionsAccessing Route Data

Metadata

Metadata & SEOOpen Graph & TwitterIcons & Favicons

API Routes

API Routes OverviewPlain Function HandlersHono IntegrationDynamic API Routes

Environment Variables

OverviewPrefixes & Client ExposureUsing in API Routes

Styling

CSS OverviewTailwind CSSCSS Modules

Platforms

WebWindowsmacOSLinuxAndroidiOS

Deployment

Deployment OverviewProduction ServerStatic ExportHosting Providers

A native React framework for building cross-platform applications from a single codebase.

Resources

  • Documentation
  • Plugins
  • Showcase
  • Releases

Community

  • GitHub Discussions
  • Reddit
  • Discord
  • LinkedIn

More

  • npm
  • GitHub
  • Issues
  • License

© 2026 Bini Cooperation.

Linking and Navigating

Bini.js provides built-in navigation components and hooks for fast, client-side transitions between routes without full page reloads. This page covers how to use Link, NavLink, and the navigation hooks.

Link component

The <Link> component is the primary way to navigate between routes. It extends the HTML <a> tag to provide client-side navigation, and it is auto-imported in all pages and layouts.

app
page.tsx
about
page.tsx
blog
page.tsx
/
/about
/blog
src/app/page.tsx
export default function Home() {
  return (
    <nav>
      <Link to="/">Home</Link>
      <Link to="/about">About</Link>
      <Link to="/blog">Blog</Link>
    </nav>
  )
}

Bini.js prefetches the destination route on hover and focus, so navigation feels instant. Add data-no-prefetch to a specific link to opt out.

Link props

PropTypeDescription
tostringThe destination route path
replacebooleanReplace the current entry in history instead of adding
stateanyState to persist to the location
classNamestringCSS class for styling
childrenReactNodeThe content inside the link

NavLink component

<NavLink> is a special version of <Link> that knows whether it matches the current route. Use it for navigation menus that need active-state styling.

app
layout.tsx
page.tsx
blog
page.tsx
/
/blog
src/app/components/Navigation.tsx
export default function Navigation() {
  const cls = ({ isActive }: { isActive: boolean }) =>
    isActive ? 'text-cyan-400' : 'text-white'

  return (
    <nav>
      <NavLink to="/" className={cls} end>Home</NavLink>
      <NavLink to="/about" className={cls}>About</NavLink>
      <NavLink to="/blog" className={cls}>Blog</NavLink>
    </nav>
  )
}
Good to know: Add end to the / link, otherwise it matches every route and always looks active.

NavLink props

PropTypeDescription
tostringThe destination route path
classNamefunction | stringFunction receives { isActive, isPending } or a string
stylefunction | objectFunction receives { isActive, isPending } or a style object
childrenReactNode | functionContent or render function
endbooleanOnly match the exact path, not child routes
caseSensitivebooleanMatch case-sensitively

useNavigate hook

The useNavigate hook returns a function that lets you navigate programmatically. It is auto-imported in all pages.

app
login
page.tsx
dashboard
page.tsx
/login
/dashboard
src/app/login/page.tsx
export default function LoginPage() {
  const navigate = useNavigate()

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault()
    const success = await loginUser()
    if (success) navigate('/dashboard')
  }

  return (
    <form onSubmit={handleSubmit}>
      <button type="submit">Login</button>
    </form>
  )
}

Navigate options

OptionTypeDescription
replacebooleanReplace the current entry in history
stateanyState to persist to the location
// Navigate with options
navigate('/profile', { replace: true, state: { from: 'login' } })

// Go back
navigate(-1)

// Go forward
navigate(1)

Because navigate accepts a function, you can also use it for declarative navigation. Use it when you need to redirect the user after an async action (like a login) or when a form is submitted.

useParams hook

The useParams hook returns an object of key/value pairs of the dynamic route parameters from the current URL. Wrap a folder name in square brackets, like [slug], to create a dynamic segment.

app
blog
[slug]
page.tsx
/blog/:slug
src/app/blog/[slug]/page.tsx
export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()

  return (
    <div>
      <h1>Blog Post: {slug}</h1>
    </div>
  )
}
For catch-all routes like [...slug], the value is exposed under params['*'], not the name written in the folder.

useLocation hook

The useLocation hook returns the current location object, including pathname, search, hash, and any state passed during navigation. This is useful for things like breadcrumbs.

src/app/components/Breadcrumbs.tsx
export default function Breadcrumbs() {
  const location = useLocation()
  const segments = location.pathname.split('/').filter(Boolean)

  return (
    <nav>
      <Link to="/">Home</Link>
      {segments.map((name, index) => {
        const routeTo = `/${segments.slice(0, index + 1).join('/')}`
        return (
          <Link key={routeTo} to={routeTo}>
            {name}
          </Link>
        )
      })}
    </nav>
  )
}

Location properties

PropertyTypeDescription
pathnamestringThe path of the current URL
searchstringThe query string, including the leading ?
hashstringThe URL hash, including the leading #
stateanyState passed via Link or navigate
keystringA unique key for this location entry

useSearchParams hook

The useSearchParams hook reads and updates the query string. It works like useState: you get the current params and a function to change them.

src/app/shop/page.tsx
export default function ShopPage() {
  const [searchParams, setSearchParams] = useSearchParams()
  const category = searchParams.get('category') || 'all'

  return (
    <div>
      <p>Category: {category}</p>
      <button onClick={() => setSearchParams({ category: 'shoes' })}>
        Show shoes
      </button>
    </div>
  )
}

Navigation with query parameters

You can include a query string directly in the to prop of <Link> or in the path you pass to navigate. The destination page reads the values with useSearchParams.

src/app/components/Filters.tsx
export default function Filters() {
  const navigate = useNavigate()

  return (
    <div>
      <Link to="/shop?category=shoes">Shoes</Link>
      <Link to={{ pathname: '/shop', search: '?category=hats&sort=price' }}>
        Hats
      </Link>
      <button onClick={() => navigate('/shop?category=bags')}>Bags</button>
    </div>
  )
}

Best practices

  • Use <Link> for standard navigation links.
  • Use <NavLink> for navigation menus that need active-state styling.
  • Use useNavigate for programmatic navigation, such as redirects after a form or login.
  • Use useParams to access dynamic route parameters.
  • Use useSearchParams for managing query strings and filters.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Routing

Define routes from the filesystem with folder-based and file-based conventions.

Dynamic Routes

Match URL segments with dynamic parameters and catch-alls.

API Routes

Add backend endpoints with plain functions or a full Hono app.

Metadata & SEO

Control titles, descriptions, and social previews per route.

Deployment

Deploy to Node, Vercel, Netlify, Cloudflare, or Deno, or build native apps in CI.

Was this helpful?
PreviousLayouts and Pages
NextFolder-Based Routing

On this page

  • Link component
  • NavLink component
  • useNavigate hook
  • useParams hook
  • useLocation hook
  • useSearchParams hook
  • Navigation with query parameters
  • Best practices
Edit this page on GitHub

Linking and Navigating

Bini.js provides built-in navigation components and hooks for fast, client-side transitions between routes without full page reloads. This page covers how to use Link, NavLink, and the navigation hooks.

Link component

The <Link> component is the primary way to navigate between routes. It extends the HTML <a> tag to provide client-side navigation, and it is auto-imported in all pages and layouts.

app
page.tsx
about
page.tsx
blog
page.tsx
/
/about
/blog
src/app/page.tsx
export default function Home() {
  return (
    <nav>
      <Link to="/">Home</Link>
      <Link to="/about">About</Link>
      <Link to="/blog">Blog</Link>
    </nav>
  )
}

Bini.js prefetches the destination route on hover and focus, so navigation feels instant. Add data-no-prefetch to a specific link to opt out.

Link props

PropTypeDescription
tostringThe destination route path
replacebooleanReplace the current entry in history instead of adding
stateanyState to persist to the location
classNamestringCSS class for styling
childrenReactNodeThe content inside the link

NavLink component

<NavLink> is a special version of <Link> that knows whether it matches the current route. Use it for navigation menus that need active-state styling.

app
layout.tsx
page.tsx
blog
page.tsx
/
/blog
src/app/components/Navigation.tsx
export default function Navigation() {
  const cls = ({ isActive }: { isActive: boolean }) =>
    isActive ? 'text-cyan-400' : 'text-white'

  return (
    <nav>
      <NavLink to="/" className={cls} end>Home</NavLink>
      <NavLink to="/about" className={cls}>About</NavLink>
      <NavLink to="/blog" className={cls}>Blog</NavLink>
    </nav>
  )
}
Good to know: Add end to the / link, otherwise it matches every route and always looks active.

NavLink props

PropTypeDescription
tostringThe destination route path
classNamefunction | stringFunction receives { isActive, isPending } or a string
stylefunction | objectFunction receives { isActive, isPending } or a style object
childrenReactNode | functionContent or render function
endbooleanOnly match the exact path, not child routes
caseSensitivebooleanMatch case-sensitively

useNavigate hook

The useNavigate hook returns a function that lets you navigate programmatically. It is auto-imported in all pages.

app
login
page.tsx
dashboard
page.tsx
/login
/dashboard
src/app/login/page.tsx
export default function LoginPage() {
  const navigate = useNavigate()

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault()
    const success = await loginUser()
    if (success) navigate('/dashboard')
  }

  return (
    <form onSubmit={handleSubmit}>
      <button type="submit">Login</button>
    </form>
  )
}

Navigate options

OptionTypeDescription
replacebooleanReplace the current entry in history
stateanyState to persist to the location
// Navigate with options
navigate('/profile', { replace: true, state: { from: 'login' } })

// Go back
navigate(-1)

// Go forward
navigate(1)

Because navigate accepts a function, you can also use it for declarative navigation. Use it when you need to redirect the user after an async action (like a login) or when a form is submitted.

useParams hook

The useParams hook returns an object of key/value pairs of the dynamic route parameters from the current URL. Wrap a folder name in square brackets, like [slug], to create a dynamic segment.

app
blog
[slug]
page.tsx
/blog/:slug
src/app/blog/[slug]/page.tsx
export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()

  return (
    <div>
      <h1>Blog Post: {slug}</h1>
    </div>
  )
}
For catch-all routes like [...slug], the value is exposed under params['*'], not the name written in the folder.

useLocation hook

The useLocation hook returns the current location object, including pathname, search, hash, and any state passed during navigation. This is useful for things like breadcrumbs.

src/app/components/Breadcrumbs.tsx
export default function Breadcrumbs() {
  const location = useLocation()
  const segments = location.pathname.split('/').filter(Boolean)

  return (
    <nav>
      <Link to="/">Home</Link>
      {segments.map((name, index) => {
        const routeTo = `/${segments.slice(0, index + 1).join('/')}`
        return (
          <Link key={routeTo} to={routeTo}>
            {name}
          </Link>
        )
      })}
    </nav>
  )
}

Location properties

PropertyTypeDescription
pathnamestringThe path of the current URL
searchstringThe query string, including the leading ?
hashstringThe URL hash, including the leading #
stateanyState passed via Link or navigate
keystringA unique key for this location entry

useSearchParams hook

The useSearchParams hook reads and updates the query string. It works like useState: you get the current params and a function to change them.

src/app/shop/page.tsx
export default function ShopPage() {
  const [searchParams, setSearchParams] = useSearchParams()
  const category = searchParams.get('category') || 'all'

  return (
    <div>
      <p>Category: {category}</p>
      <button onClick={() => setSearchParams({ category: 'shoes' })}>
        Show shoes
      </button>
    </div>
  )
}

Navigation with query parameters

You can include a query string directly in the to prop of <Link> or in the path you pass to navigate. The destination page reads the values with useSearchParams.

src/app/components/Filters.tsx
export default function Filters() {
  const navigate = useNavigate()

  return (
    <div>
      <Link to="/shop?category=shoes">Shoes</Link>
      <Link to={{ pathname: '/shop', search: '?category=hats&sort=price' }}>
        Hats
      </Link>
      <button onClick={() => navigate('/shop?category=bags')}>Bags</button>
    </div>
  )
}

Best practices

  • Use <Link> for standard navigation links.
  • Use <NavLink> for navigation menus that need active-state styling.
  • Use useNavigate for programmatic navigation, such as redirects after a form or login.
  • Use useParams to access dynamic route parameters.
  • Use useSearchParams for managing query strings and filters.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Routing

Define routes from the filesystem with folder-based and file-based conventions.

Dynamic Routes

Match URL segments with dynamic parameters and catch-alls.

API Routes

Add backend endpoints with plain functions or a full Hono app.

Metadata & SEO

Control titles, descriptions, and social previews per route.

Deployment

Deploy to Node, Vercel, Netlify, Cloudflare, or Deno, or build native apps in CI.

Was this helpful?
PreviousLayouts and Pages
NextFolder-Based Routing

On this page

  • Link component
  • NavLink component
  • useNavigate hook
  • useParams hook
  • useLocation hook
  • useSearchParams hook
  • Navigation with query parameters
  • Best practices
Edit this page on GitHub