Navigation
Handle client-side transitions between routes using the Link component or programmatic hooks.
The <Link> Component
The <Link> component is the primary way to navigate in Dinou. It extends the standard HTML anchor element to provide client-side soft navigation (SPA transitions) and automatic performance optimizations.
"use client";
import { Link } from "dinou";
export default function NavBar() {
return (
<nav className="flex gap-4">
<Link href="/">Home</Link>
<Link href="/about">About</Link>
{/* Opt-in for fresh data */}
<Link href="/dashboard" fresh>
Live Dashboard
</Link>
</nav>
);
}By default, Dinou prefetches the code and data for the destination route when the user hovers over the link.
Passing the fresh prop bypasses the Client Router Cache and forces a fetch of the latest data from the server. Ideal for volatile content.
Native Elements
<a> tags also trigger client-side soft navigation via global event delegation in Dinou, but they lack the smart features (prefetching, fresh prop) provided by the <Link> component.Show Technical Details (for Ejected Code)
In the ejected core, the link and global navigation logic are managed by the following modules:
dinou/core/link.jsx: The<Link>component intercepts clicks (preventing default browser reloads) and forwards navigations to the Router viauseRouter().push(href, { fresh }). It also binds toonMouseEnterto runwindow.__DINOU_PREFETCH__(resolvedHref)when hovered.dinou/core/navigation.js: Implements the client-side context hooks (useRouter,usePathname, anduseSearchParams). Note how these hooks share code pathways between server-side SSR execution (falling back to reading request context dynamically) and client-side execution (reading fromRouterContext).
Relative Routing Rules
Dinou resolves relative navigation paths (e.g., about, ./about, or ../dashboard) using a File-System Directory Convention. This differs from standard browser URL resolution:
In a standard web browser, a URL like /blog/hello (lacking a trailing slash) treats hello as a file name. A relative link about resolves by replacing it, yielding /blog/about.
Dinou's Convention: Every route is treated as a directory because physically, pages are folders containing a page.tsx component (e.g. src/blog/hello/page.tsx). Resolving relatively relative to the page mimics navigating the file structure of your project.
| Current Path | Relative Target | Resolved Path |
|---|---|---|
| /blog/hello | about | /blog/hello/about |
| /blog/hello | ./about | /blog/hello/about |
| /blog/hello | ../about | /blog/about |
This rule applies uniformly across all navigation methods, including the <Link> component and programmatic calls like router.push().