Experience end-to-end static type safety across your entire application. Dinou combines sub-2ms route type generation with intelligent TypeScript module augmentation, delivering instant dev-time IDE autocomplete and dead-link prevention with zero runtime cost.
Dinou introduces a built-in, two-level Type-Safe Routing system designed from the ground up to give developers full confidence when building and refactoring applications. Unlike traditional routing setups that require external schema validators or proprietary bundler plugins, Dinou generates strict TypeScript declaration files directly from your src/ filesystem conventions.
The type system elevates developer experience across two fundamental dimensions:
Instant autocomplete for all valid project paths inside <Link href="..."> (or to="..."), router.push("..."), and router.replace("...").
Catches typos, deleted routes, and broken URLs in your IDE at dev time and via npm run typegen && npx tsc --noEmit before code ever reaches production.
Strict parameter & slot typing across page.tsx, intermediate layout.tsx, parallel @slot/page.tsx, error.tsx, not_found.tsx, and page_functions.ts / layout_functions.ts via PageProps, LayoutProps, SlotProps, ErrorProps, NotFoundProps, PageFunctions, LayoutFunctions, and RouteParams.
Supports Dinou's Horizontal Segmentation natively: intermediate layouts without a sibling page.tsx and parallel @slots are fully typed without exposing non-page folders or @slots as valid <Link> URLs.
Dinou's route registry lives exclusively at the TypeScript layer inside auto-generated .d.ts declaration files—shipping 0 bytes of generated route manifests regardless of whether your project has 10 routes or 1,000 routes.
params={{ ... }} substitution uses a tiny built-in segment interpolator in Dinou's core navigation helper—no generated runtime route tables or validators.Import Link or useRouter from "dinou". Your IDE immediately suggests (Ctrl + Space) and strictly validates all navigable static routes, dynamic route patterns (with required typed params), and relative paths anchored with from (both "sub" and "./sub", plus "../...") across <Link href="..."> (and its to alias), router.push(), and router.replace(). It also validates dynamic template strings (`/blog/${slug}`) and route suffixes (?query, #hash), while permitting standalone queries/hashes (?tab=1, #top) and external protocols (http://, https://, mailto:, tel:):
import { Link } from "dinou";
export function Navbar({ post }: { post: { slug: string } }) {
return (
<nav className="flex gap-4">
{/* ✅ Instant Ctrl + Space autocompletion for BOTH static & dynamic routes */}
<Link href="/docs/routing">Routing Guide</Link>
{/* ✅ Option A: Autocompleted dynamic pattern + required typed params */}
<Link href="/blog/[slug]" params={{ slug: post.slug }}>
View Post
</Link>
{/* ✅ Option B: Direct template string interpolation (no params prop needed) */}
<Link to={`/blog/${post.slug}`}>View Post (Template)</Link>
{/* ✅ Strict relative navigation anchored with from ("sub", "./sub", "../...") */}
<Link from="/docs/routing" to="../navigation">
Navigation Guide (Relative)
</Link>
{/* ✅ Seamless support for queries, hashes, and external URLs */}
<Link href="/demo?tab=settings#section-1">Settings</Link>
<Link href="https://github.com/roggc/dinou">GitHub</Link>
<Link href="mailto:[email protected]">Contact</Link>
{/* ❌ TypeScript error: [slug] pattern cannot be used without params! */}
{/* <Link href="/blog/[slug]">Forgot params</Link> */}
{/* ❌ TypeScript error: relative paths require from (catches "./subs" typos!) */}
{/* <Link to="./subs">Unanchored Relative</Link> */}
{/* ❌ TypeScript error when pointing to a non-existent route */}
{/* <Link href="/unknown-route" /> */}
</nav>
);
}"use client";
import { useRouter } from "dinou";
export function NavActions({ slug }: { slug: string }) {
const router = useRouter();
return (
<div className="flex gap-2">
{/* ✅ Autocompletes static & dynamic route patterns */}
<button onClick={() => router.push("/docs/api-reference")}>
View API Reference
</button>
{/* ✅ Option A: Dynamic route pattern + required typed { params } */}
<button
onClick={() =>
router.push("/blog/[slug]", { params: { slug }, fresh: true })
}
>
Reload Post Fresh
</button>
{/* ✅ Option B: Direct template string interpolation */}
<button onClick={() => router.replace(`/blog/${slug}`)}>
Replace Post URL
</button>
{/* ✅ Strict relative navigation anchored with { from } */}
<button
onClick={() => router.push("../navigation", { from: "/docs/routing" })}
>
Relative Push
</button>
{/* ❌ TypeScript error: missing { params: { slug } } */}
{/* <button onClick={() => router.push("/blog/[slug]")} /> */}
{/* ❌ TypeScript error: relative path without { from } */}
{/* <button onClick={() => router.push("./subs")} /> */}
{/* ❌ TypeScript error: unknown route */}
{/* <button onClick={() => router.push("/typo-route")} /> */}
</div>
);
}Pass your segment pattern as a generic argument to PageProps, LayoutProps, SlotProps, PageFunctions, LayoutFunctions, or RouteParams when importing from "dinou"—or import them from "./dinou" inside any route folder to get both pre-bound types and pre-bound relative <Link> / useRouter() with zero route strings! Both PageProps<TRoute, TProps> and LayoutProps<TLayout, TProps> also accept custom props returned by getProps:
import type { PageProps } from "dinou";
import type { BlogPostData } from "./page_functions";
export default function BlogPost({
params,
postTitle,
}: PageProps<"/blog/[slug]", BlogPostData>) {
// ✅ params.slug is string; postTitle is inferred from BlogPostData
return <h1>{postTitle} ({params.slug})</h1>;
// ❌ TypeScript error: Property 'id' does not exist on type '{ slug: string }'
// return <h1>{params.id}</h1>;
}import type { LayoutProps } from "dinou";
export default function BlogLayout({
children,
params,
}: LayoutProps<"/blog/[slug]">) {
// ✅ params.slug is strongly typed; children is typed as ReactNode
return (
<section>
<header>Post: {params.slug}</header>
<main>{children}</main>
</section>
);
}import type { PageFunctions } from "dinou";
export interface BlogPostData {
postTitle: string;
}
// ✅ Types both params?.slug and the returned BlogPostData contract
export const getProps: PageFunctions<
"/blog/[slug]",
BlogPostData
>["getProps"] = async (params) => {
return {
postTitle: `Post: ${params?.slug}`,
};
};
export const validateParams: PageFunctions<
"/blog/[slug]"
>["validateParams"] = (params) => {
return Boolean(params?.slug && /^[a-z0-9-]+$/.test(params.slug));
};import type { RouteParams } from "dinou";
// ✅ Directly types standalone helpers, data loaders, or services
export async function loadPostByRoute(params: RouteParams<"/blog/[slug]">) {
return fetchPost(params.slug);
}Because Dinou features Horizontal Segmentation (independent lifecycles for layouts, parallel @slots, and pages), the route topology scanner indexes intermediate layouts—even when a folder has no sibling page.tsx—and automatically infers parallel @slot props on LayoutProps:
import type { LayoutProps } from "dinou";
import type { OrgLayoutData } from "./layout_functions";
// Folder has layout.tsx + @sidebar/page.tsx + @analytics/page.tsx,
// and NO sibling page.tsx (leaf pages live under projects/[projectId]/page.tsx)
export default function WorkspaceLayout({
children,
params,
sidebar,
analytics,
orgPlan,
}: LayoutProps<"/workspace/[org]", OrgLayoutData>) {
// ✅ params.org is string (child projectId does NOT leak into parent layout!)
// ✅ sidebar?: ReactNode & analytics?: ReactNode are auto-inferred from @slots!
return (
<div className="grid grid-cols-[240px_1fr_320px]" data-plan={orgPlan}>
<aside>{sidebar}</aside>
<main data-org={params.org}>{children}</main>
<aside>{analytics}</aside>
</div>
);
}import type { LayoutFunctions } from "dinou";
export interface OrgLayoutData {
orgPlan: "free" | "pro";
}
// ✅ Intermediate layout_functions.ts works even without a sibling page.tsx
export const getProps: LayoutFunctions<
"/workspace/[org]",
OrgLayoutData
>["getProps"] = async (params) => {
// params?.org is typed as string | undefined
return { orgPlan: params?.org === "acme" ? "pro" : "free" };
};
export const validateParams: LayoutFunctions<
"/workspace/[org]"
>["validateParams"] = (params) => Boolean(params?.org);import type { SlotProps } from "dinou";
// ✅ SlotProps (or PageProps<"/workspace/[org]/@analytics">) types cumulative params
export default async function AnalyticsSlot({
params,
}: SlotProps<"/workspace/[org]/@analytics">) {
// params.org is string — propagated at runtime & statically typed in TypeScript!
return <section>Live metrics for {params.org}</section>;
}import { Link, type PageProps } from "dinou";
export default function ProjectPage({
params,
}: PageProps<"/workspace/[org]/projects/[projectId]">) {
// ✅ Leaf page receives cumulative { org: string; projectId: string }
return (
<article>
<h1>{params.org} / Project #{params.projectId}</h1>
<Link href={`/workspace/${params.org}/projects/${params.projectId}`}>
Permalink
</Link>
{/* ❌ TypeScript error: /workspace/[org] has no page.tsx, so it is NOT navigable! */}
{/* <Link href={`/workspace/${params.org}`}>Invalid Workspace Root</Link> */}
</article>
);
}To keep application code clean and expressive, Dinou distills routing type-safety down to primary types exported directly from "dinou":
| Exported Type | Primary Purpose | Canonical Example |
|---|---|---|
| PageProps<T, P?> | Page components (page.tsx, not_found.tsx, or @slot/page.tsx) + optional getProps payload P | Page({ params }: PageProps<"/blog/[slug]", Data>) |
| LayoutProps<T, P?> | Layouts (including intermediate folders without page.tsx) with auto-inferred @slot props + optional P | Layout({ children, params, sidebar }: LayoutProps<"/workspace/[org]">) |
| SlotProps<T> | Parallel Slot Page components (@slot/page.tsx) | Slot({ params }: SlotProps<"/workspace/[org]/@analytics">) |
| ErrorProps<T> | Error boundaries across routes, intermediate folders & @slot/error.tsx | Error({ error, params }: ErrorProps<"/workspace/[org]/@analytics">) |
| NotFoundProps<T, P?> | 404 boundaries (not_found.tsx) across root, routes & intermediate folders + optional P | NotFound({ params }: NotFoundProps<"/workspace/[org]">) |
| PageFunctions<T, P> | Page lifecycle & data contracts (page_functions.ts) | const getProps: PageFunctions<"/blog/[slug]", Data>["getProps"] |
| LayoutFunctions<T, P> | Layout lifecycle & data contracts (layout_functions.ts, including intermediate layouts) | const validateParams: LayoutFunctions<"/workspace/[org]">["validateParams"] |
| RouteParams<T> | Standalone helpers across page, layout, or @slot segments | loadPost(params: RouteParams<"/blog/[slug]">) |
| DinouRoute | Resolved navigable URLs (static, interpolated, query/hash, external) for custom nav props & menus | interface NavProps { href: DinouRoute } |
| DinouLinkTarget | Union of DinouRoute plus raw dynamic patterns (e.g. "/blog/[slug]") accepted by <Link> & useRouter() | type Target = DinouLinkTarget |
| LinkProps<TFrom, THref> | Powers <Link> & useRouter() with static/dynamic pattern autocomplete, conditional params, and strict relative from | <Link from="/blog/[slug]" to="comments"> |
PageProps vs. Semantic Aliases vs. Dedicated TypesNotFoundProps & SlotProps): Both not_found.tsx and @slot/page.tsx receive the exact same { params } runtime contract as page.tsx. You can freely use PageProps in all three files, or use NotFoundProps / SlotProps for semantic clarity and narrower Ctrl + Space autocomplete (e.g., SlotProps filters suggestions strictly to @slot folders, while NotFoundProps hides @slot paths and already recognizes intermediate layout folders).LayoutProps & ErrorProps): These are not aliases of PageProps—always use them for their respective files:LayoutProps in layout.tsx: Injects children: ReactNode, auto-infers sibling parallel @slot props (sidebar?: ReactNode, etc.), and validates against DinouLayoutParamsMap—allowing intermediate layouts without a sibling page.tsx (where PageProps intentionally errors).ErrorProps in error.tsx & @slot/error.tsx: Injects error: Error alongside params (which PageProps does not include) and validates against DinouErrorParamsMap (supporting error-only intermediate folders).Dinou deterministically transforms your file-system folder naming conventions into strict TypeScript definitions:
| Filesystem Convention | Inferred Parameter Type | Route Example | Type of params |
|---|---|---|---|
| Static Route | No parameters | src/about/page.tsx | Record<string, never> |
Single Dynamic [id] | string | src/blog/[id]/page.tsx | { id: string } |
Catch-All [...slug] | string[] | src/docs/[...slug]/page.tsx | { slug: string[] } |
Optional Dynamic [[lang]] | string | undefined | src/[[lang]]/page.tsx | { lang?: string } |
Optional Catch-All [[...opt]] | string[] ([] on base; optional in <Link params>) | src/shop/[[...opt]]/page.tsx | { opt: string[] } |
| Multiple Dynamic Segments | Combined by segment | src/users/[uId]/posts/[pId] | { uId: string; pId: string } |
| Nested Optionals | Positional dependent | src/inv/[[wh]]/[[aisle]] | { wh?: string; aisle?: string } |
For routes containing optional segments ([[slug]] or [[...opt]]), Dinou automatically registers both the parameterized path and the base route where the segment is omitted.
For example, with src/products/[[category]]/page.tsx, both <Link href="/products" /> and <Link href="/products/electronics" /> are valid, autocompleted routes.
In TypeScript, template literal types evaluate ${string} as matching any string, including the empty string "" (because "" extends string is true).
The scenario: Consider a nested route such as src/posts/[id]/[slug]/page.tsx, whose generated template literal type is `/posts/${string | number}/${string | number}`.
If a developer accidentally leaves off the second parameter but appends a trailing slash:
TypeScript matches the first parameter with id, the slash with literal /, and the second parameter with empty string "". However, at runtime Dinou normalizes trailing slashes, requesting /posts/123 (which results in a 404 Not Found because no page.tsx exists at the parent segment).
Best Practice: Always avoid trailing slashes when building dynamic URLs. Written without the trailing slash (`/posts/${id}`), TypeScript accurately flags the missing parameter in your IDE and when running npm run typegen && npx tsc --noEmit.
Press Ctrl + Space (or Cmd + Space) inside quotes across navigation props (<Link from="" to="">, <Link href="">, router.push("")) and segment prop generics (PageProps<"">, LayoutProps<"">):
import { Link, type PageProps } from "dinou";
// 1. Trigger Ctrl + Space inside PageProps<""> to pick any route pattern
export default function BlogPost({ params }: PageProps<"/blog/[slug]">) {
return (
<article>
<h1>{params.slug}</h1>
{/* 2. Trigger Ctrl + Space inside to="" — lists BOTH static routes AND
dynamic patterns like "/blog/[slug]", then autocompletes params! */}
<Link to="/blog/[slug]" params={{ slug: "next-article" }}>
Next Article
</Link>
{/* 3. Trigger Ctrl + Space inside from="" (picks the source folder),
then inside to="" (suggests "comments", "./comments", ".", "../..", etc.) */}
<Link from="/blog/[slug]" to="comments">
View Comments
</Link>
</article>
);
}Error boundaries (error.tsx and @slot/error.tsx) receive error: Error and params via ErrorProps<T>, while custom 404 boundaries (not_found.tsx—including intermediate directory 404 boundaries without a sibling page.tsx) receive cumulative params (plus any sibling page_functions.ts getProps data) via NotFoundProps<T, P?>:
"use client";
import { useRouter, type ErrorProps } from "dinou";
export default function BlogPostError({
params,
error,
}: ErrorProps<"/blog/[slug]">) {
const router = useRouter();
return (
<div className="error-card p-6 border rounded-xl bg-destructive/10">
<h2>Failed to load post: {params.slug}</h2>
<p className="text-sm text-muted-foreground">{error.message}</p>
{/* Soft reload via Dinou client router */}
<button onClick={() => router.refresh()}>Try Again</button>
</div>
);
}"use client";
import { useRouter, type ErrorProps } from "dinou";
export default function AnalyticsSlotError({
params,
error,
}: ErrorProps<"/dashboard/[org]/@analytics">) {
const router = useRouter();
return (
<aside className="p-4 border rounded-lg bg-amber-500/10">
<h3>Analytics unavailable for {params.org}</h3>
<p className="text-xs text-muted-foreground">{error.message}</p>
{/* Re-fetch layout & parallel slots without full browser reload */}
<button onClick={() => router.refresh({ layout: true })}>
Retry Widget
</button>
</aside>
);
}"use client";
import { useRouter, type ErrorProps } from "dinou";
// Catches unhandled errors thrown by any nested child route under /workspace/[org]/*
export default function WorkspaceError({
params,
error,
}: ErrorProps<"/workspace/[org]">) {
const router = useRouter();
return (
<div className="p-6 border rounded-xl bg-destructive/10">
<h2>Workspace error in {params.org}</h2>
<p className="text-sm text-muted-foreground">{error.message}</p>
<button onClick={() => router.refresh()}>Retry</button>
</div>
);
}import { Link, type NotFoundProps } from "dinou";
// Catches 404s under /workspace/[org]/* (or validateParams returning false),
// even when /workspace/[org] has NO sibling page.tsx!
export default function WorkspaceNotFound({
params,
}: NotFoundProps<"/workspace/[org]">) {
return (
<section className="p-6 border rounded-xl">
<h2>Nothing found in workspace “{params.org}”</h2>
<Link href="/">Back to Home</Link>
</section>
);
}When building reusable UI components (custom buttons, navigation tabs, or breadcrumb menus) that accept already-resolved URLs, type their destination props with DinouRoute (or use DinouLinkTarget if your config/wrapper also accepts raw "/blog/[slug]" route patterns) to give your design system native static link validation in your IDE and tsc:
import { Link, type DinouRoute } from "dinou";
interface NavButtonProps {
href: DinouRoute; // 👈 Inherits full autocompletion and route validation
label: string;
}
export function NavButton({ href, label }: NavButtonProps) {
return (
<Link
href={href}
className="px-3 py-1.5 rounded-lg bg-blue-600 text-white font-medium"
>
{label}
</Link>
);
}import type { DinouRoute } from "dinou";
import { NavButton } from "./nav-button";
const menu: { label: string; href: DinouRoute }[] = [
{ label: "Overview", href: "/docs" }, // ✅ Autocompleted
{ label: "Routing", href: "/docs/routing" }, // ✅ Autocompleted
// { label: "Broken", href: "/non-existent-page" }, // ❌ TypeScript error!
];
export function Sidebar() {
return (
<aside className="flex flex-col gap-2">
{menu.map((item) => (
<NavButton key={item.href} href={item.href} label={item.label} />
))}
</aside>
);
}Dinou supports two coexisting, type-safe styles for navigating to dynamic routes in <Link> (href and to), router.push(), and router.replace():
params: Gives you full Ctrl + Space IDE autocomplete for dynamic routes too (because TypeScript only displays finite string literals in completion menus), auto-encodes values via encodeURIComponent, supports catch-all arrays ([...slug]) and optional segments ([[lang]]), and strictly requires params whenever a required [param] bracket appears in the pattern.`/products/${product.id}`) with zero params prop, verified against generated template literal route types while still blocking accidentally uninterpolated [param] placeholders."use client";
import { Link, useRouter } from "dinou";
interface Product {
id: string;
name: string;
}
export function ProductCard({ product }: { product: Product }) {
const router = useRouter();
return (
<div className="card p-4 border rounded-xl space-y-2">
{/* ✅ Style 1: Autocompleted dynamic pattern + required typed params */}
<Link to="/products/[id]" params={{ id: product.id }}>
{product.name}
</Link>
{/* ✅ Catch-all & optional segments with params */}
<Link to="/docs/[...slug]" params={{ slug: ["guides", "routing"] }}>
Routing Docs
</Link>
<Link to="/i18n/[[lang]]">Default Locale</Link>
{/* ✅ Style 2: Direct template string interpolation (no params needed) */}
<Link href={`/products/${product.id}`}>{product.name} (Direct)</Link>
{/* ✅ Both styles work identically in router.push() and router.replace() */}
<button
onClick={() =>
router.push("/products/[id]", { params: { id: product.id }, fresh: true })
}
>
View Details
</button>
<button onClick={() => router.replace(`/products/${product.id}`)}>
Quick Replace
</button>
{/* ❌ Compile-time error: [id] can NEVER slip into the URL without params! */}
{/* <Link to="/products/[id]">Broken</Link> */}
{/* <button onClick={() => router.push("/products/[id]")} /> */}
</div>
);
}fromAt static analysis time, TypeScript cannot infer which URL is currently mounted in the browser—especially inside shared components, persistent layouts, or parallel @slots. To guarantee zero unvalidated relative links, Dinou rejects unanchored relative paths (such as to="./subs", to="./sub", or to="sub" without from) and unlocks exact, filesystem-grade relative routing whenever you specify from:
Ctrl + Space Autocomplete on Both from and to / href: Inside from="", your IDE suggests every route and intermediate directory prefix in your project (e.g., "/workspace", "/workspace/[org]", "/workspace/[org]/contact", also accepting patterns without a leading slash like "workspace/[org]/contact"). Once from is set, to="" / href="" suggests only the exact finite set of valid navigable relative paths from that folder."sub" and "./sub" + Non-Page Parent Exclusion: Just like cd sub and cd ./sub in a terminal, Dinou treats every route as a directory. Both "sub" and "./sub" (plus ".", "../..", and valid siblings) appear in autocomplete, while typos ("subs", "./subs") and intermediate parent directories without a page.tsx (e.g., ".." when /workspace/[org] only has a layout.tsx) are automatically excluded and rejected!from="/workspace/[org]/contact" to to="sub") reuses the active [org] value already in the browser URL at runtime—no params prop needed! You only pass params when the relative target itself enters a new dynamic child segment (e.g., from="/workspace" + to="[org]/contact/sub").layout.tsx & Parallel @slots: Because @slot folders (like @sidebar) do not appear in browser URLs, anchor relative links inside src/workspace/[org]/@sidebar/page.tsx to their URL segment from="/workspace/[org]". Even when the browser is on a deeper child route like /workspace/acme/contact/sub, Dinou slices the runtime base pathname back to /workspace/acme so to="contact" always resolves cleanly to /workspace/acme/contact.useRouter(): Both router.push(relativeHref, { from }) and router.replace(relativeHref, { from, fresh }) share the exact same autocomplete, parameter rules, and runtime base slicing.from Boilerplate? Inside any route folder, import { Link, useRouter } from "./dinou" (see Section 4.6 below) so from is pre-filled automatically from that folder!"use client";
import { Link, useRouter } from "dinou";
// Assuming src/workspace/page.tsx, src/workspace/[org]/contact/page.tsx,
// and src/workspace/[org]/contact/sub/page.tsx exist (no page.tsx at /workspace/[org]):
export function ContactActions({ nextOrg }: { nextOrg: string }) {
const router = useRouter();
return (
<nav className="flex flex-wrap gap-3">
{/* ✅ Bare child ("sub") and dot-slash ("./sub") both autocomplete & validate! */}
{/* Active [org] is inherited from the browser URL — no params needed */}
<Link from="/workspace/[org]/contact" to="sub">
Subpage (cd sub)
</Link>
<Link from="/workspace/[org]/contact" to="./sub">
Subpage (cd ./sub)
</Link>
{/* ✅ Parent navigation: "../.." resolves to /workspace (has page.tsx) */}
<Link from="/workspace/[org]/contact" to="../..">
Back to Workspace Hub
</Link>
{/* ✅ Entering a NEW dynamic child segment from a parent route requires params */}
<Link from="/workspace" to="[org]/contact/sub" params={{ org: nextOrg }}>
Switch Org Subpage
</Link>
{/* ✅ Programmatic push() and replace() support { from } identically */}
<button
onClick={() => router.push("sub", { from: "/workspace/[org]/contact" })}
>
Push Subpage
</button>
<button
onClick={() =>
router.replace("../..", { from: "/workspace/[org]/contact", fresh: true })
}
>
Replace to Hub
</button>
{/* ❌ Compile-time error: ".." points to /workspace/[org], which has NO page.tsx! */}
{/* <Link from="/workspace/[org]/contact" to="..">Missing parent page</Link> */}
{/* ❌ Compile-time error: typo in relative target */}
{/* <Link from="/workspace/[org]/contact" to="subs">Typo</Link> */}
{/* <Link from="/workspace/[org]/contact" to="./subs">Typo</Link> */}
{/* ❌ Compile-time error: unanchored relative path without from */}
{/* <Link to="./sub">Missing from</Link> */}
{/* <Link to="sub">Missing from</Link> */}
</nav>
);
}import { Link, type SlotProps } from "dinou";
export default function WorkspaceSidebar({
params,
}: SlotProps<"/workspace/[org]/@sidebar">) {
return (
<aside className="space-y-2">
<h3>Org: {params.org}</h3>
{/* ✅ @sidebar is not part of the URL, so anchor from="/workspace/[org]"!
Even if the user is deep inside /workspace/acme/contact/sub,
Dinou slices the base pathname to /workspace/acme -> /workspace/acme/contact */}
<Link from="/workspace/[org]" to="contact">
Contact Overview
</Link>
<Link from="/workspace/[org]" to="contact/sub">
Contact Subpage
</Link>
</aside>
);
}"./dinou")Inside any route folder in src/ (pages, intermediate layouts, route groups (group), and parallel @slots), you can import directly from "./dinou" instead of "dinou" (or "../dinou" from a colocated components/ subfolder—do not prefix active subfolders with _, as _* directories are reserved for parked/disabled code). Powered by TypeScript's rootDirs: ["src", ".dinou/routes"], Dinou generates a zero-pollution virtual module per route folder without touching your src/ directory:
PageProps, LayoutProps (including auto-inferred sibling @slot props!), SlotProps, ErrorProps, NotFoundProps, PageFunctions, LayoutFunctions, and RouteParams are pre-bound to that folder's exact route segment—no string generic needed! If you rename a folder, every type and relative link updates automatically.from on <Link> & Memoized useRouter(): Both Link and useRouter() imported from "./dinou" are pre-bound to that folder's URL origin (ROUTE), with useRouter() memoized for referential stability across re-renders. Pressing Ctrl + Space inside <Link to=""> or router.push("") immediately suggests and validates both strict relative targets ("sub", "./sub", "../..") and absolute static/dynamic routes—without writing from!"dinou" Parity: "./dinou" also exports the folder's literal ROUTE constant alongside all standard runtime utilities (redirect, ClientRedirect, usePathname, useSearchParams, getContext, noDynamic, refreshSlot, useNavigationLoading, defineConfig) and TypeScript helper types (DinouEnv, RequestContextStore, ResponseProxy, DinouConfig, DinouPlugin, DinouRoute, DinouLinkTarget, StaticPathParams, etc.), so route files only need one unified import."./dinou" vs. "dinou": Reach for "./dinou" specifically when a route file needs folder-contextual types (PageProps, LayoutProps, PageFunctions, etc.) or relative navigation without repeating from. For shared UI components (src/components/), utilities (src/lib/), or components that only perform absolute navigation and universal hooks, prefer importing from "dinou" so those modules remain decoupled from any folder path. Global shared folders like src/components/ intentionally do not receive "./dinou" (failing immediately with TS2307 if misused), and you should avoid naming a local file or subfolder dinou inside a route folder so it does not shadow "./dinou"."use client";
// 👇 Single unified import — pre-bound to "/workspace/[org]/contact"!
import { Link, useRouter, ROUTE, type PageProps } from "./dinou";
export default function ContactPage({ params }: PageProps<{ title?: string }>) {
// ✅ params.org is string — WITHOUT writing PageProps<"/workspace/[org]/contact">!
// ✅ ROUTE is typed as literal "/workspace/[org]/contact"
const router = useRouter();
return (
<section data-route={ROUTE}>
<h1>Contact {params.org}</h1>
{/* ✅ Relative links autocomplete & validate WITHOUT passing from! */}
<Link to="sub">Subpage (bare)</Link>
<Link to="./sub">Subpage (./)</Link>
<Link to="../..">Back to /workspace</Link>
{/* ✅ Absolute & dynamic routes ALSO work on the exact same <Link>! */}
<Link to="/docs/routing">Docs</Link>
<Link to="/workspace/[org]/contact/sub" params={{ org: params.org }}>
Explicit Dynamic Pattern
</Link>
{/* ✅ useRouter() is pre-bound too — no { from } needed! */}
<button onClick={() => router.push("sub")}>Push Subpage</button>
{/* ❌ Still strictly rejects typos & non-page parent ".."! */}
{/* <Link to="./subs">Typo</Link> */}
{/* <Link to="..">Parent /workspace/[org] has no page.tsx</Link> */}
</section>
);
}// Inside @sidebar, "./dinou" knows SlotProps has params: { org: string }
// AND pre-binds <Link> / useRouter() to the URL segment "/workspace/[org]"!
import { Link, type SlotProps } from "./dinou";
export default function WorkspaceSidebar({ params }: SlotProps) {
return (
<aside>
<h3>{params.org}</h3>
{/* ✅ Resolves cleanly to /workspace/<org>/contact from any child depth */}
<Link to="contact">Contact</Link>
<Link to="contact/sub">Contact Subpage</Link>
</aside>
);
}import type { LayoutProps } from "./dinou";
// ✅ LayoutProps automatically infers sibling @slot ReactNode props (e.g. sidebar)
export default function WorkspaceRootLayout({ children, sidebar }: LayoutProps) {
return (
<div className="grid grid-cols-[240px_1fr]">
<aside>{sidebar}</aside>
<main>{children}</main>
</div>
);
}Parking routes with _folder: If you temporarily disable a route folder by prefixing it with an underscore (e.g. renaming src/workspace to src/_workspace), Dinou excludes it from both the global route registry and all bundlers while still emitting fallback .dinou/routes/_workspace/**/dinou.d.ts shims—so any active links pointing to /workspace immediately surface dead-link errors, while parked files inside src/_workspace keep compiling cleanly in VS Code and tsc --noEmit without changing a single "./dinou" import.
"./dinou", "../dinou" & Folder Types)Understanding where Dinou generates contextual modules makes choosing between "./dinou", "../dinou", and "dinou" effortless. During its bottom-up scan of src/, Dinou emits .dinou/routes/<dir>/dinou.{js,d.ts} if and only if a directory:
page.*, layout.*, error.*, not_found.*, page_functions.*, or layout_functions.*), orLeaf folders that contain no route files and have no child routes below them (such as src/components/ or a colocated src/blog/[slug]/components/ folder) do not represent a URL segment and therefore do not receive their own dinou.{js,d.ts} file:
src/ ✅ Root route tree -> ROUTE = "/"
├── components/
│ └── navbar.tsx ❌ Shared non-route folder -> NO ./dinou (always import from "dinou")
├── (marketing)/
│ └── pricing/
│ └── page.tsx ✅ Route group unwrapped -> ./dinou (ROUTE = "/pricing")
├── blog/
│ └── [slug]/
│ ├── page.tsx ✅ Direct route folder -> ./dinou (ROUTE = "/blog/[slug]")
│ └── components/
│ └── post-pager.tsx 🔹 Colocated leaf subfolder -> NO ./dinou (use "dinou" or "../dinou")
├── workspace/
│ └── [org]/
│ ├── layout.tsx ✅ Intermediate layout -> ./dinou (ROUTE = "/workspace/[org]")
│ ├── @sidebar/
│ │ └── page.tsx ✅ Parallel @slot -> ./dinou (SlotProps: { org }, ROUTE = "/workspace/[org]")
│ └── projects/ ✅ Route ancestor (has child route below!) -> ./dinou (ROUTE = "/workspace/[org]/projects")
│ └── [projectId]/
│ └── page.tsx ✅ Leaf route -> ./dinou (ROUTE = "/workspace/[org]/projects/[projectId]")
└── _legacy/
└── page.tsx ⏸️ Parked (_*) -> Ignored by router/bundlers; gets fallback ./dinou shim (ROUTE: string)| Directory Type & Example | Has ./dinou? | Recommended Import | Resolution & Practical Behavior |
|---|---|---|---|
1. Direct Route Folder src/blog/[slug]/ | Yes | "./dinou" / "dinou" | Pre-binds PageProps, LayoutProps, PageFunctions, etc. and sets ROUTE = "/blog/[slug]". Colocated files in this exact same folder share "./dinou". |
2. Route Ancestor Folder src/workspace/[org]/projects/ | Yes | "./dinou" | Even with no page.tsx or layout.tsx of its own, having [projectId]/page.tsx below makes it part of the URL tree (ROUTE = "/workspace/[org]/projects", RouteParams = { org: string })—ready immediately if you add an intermediate error.tsx or not_found.tsx. |
3. Route Group (group)src/(marketing)/pricing/ | Yes | "./dinou" | Transparently strips (marketing) from the URL so ROUTE = "/pricing" while still resolving "./dinou" at the physical (marketing)/pricing/ path. |
4. Parallel @slot Foldersrc/workspace/[org]/@sidebar/ | Yes | "./dinou" | Types SlotProps / ErrorProps with cumulative { org: string }, while anchoring ROUTE, <Link>, and useRouter() to the parent URL segment "/workspace/[org]". |
5. Colocated Leaf Subfolder src/blog/[slug]/components/ | No (TS2307) | "dinou" or "../dinou" | Do not prefix active subfolders with _. Because no routes exist inside or below components/, "./dinou" is absent: use "dinou" for portable/absolute links, or "../dinou" (or "../../dinou") to inherit parent "/blog/[slug]" relative links. |
6. Global Shared Folder src/components/, src/lib/ | No (TS2307) | Always "dinou" | Shared components can mount on any URL, so they must import from "dinou" and use absolute routes (or explicit from). Never use "../dinou" here. |
7. Parked _foldersrc/_legacy/, src/blog/_draft/ | Fallback shim | Inactive only | Excluded from router & bundlers; active modules cannot import from _* (build error). Emits ROUTE: string fallback shims if parked route files exist so IDE diagnostics stay clean. |
"../dinou" Inside Global src/components/!Because src/ itself is the root of your route tree, Dinou generates a root module at .dinou/routes/dinou.{js,d.ts} bound to ROUTE = "/".
While writing import { Link } from "./dinou" inside src/components/navbar.tsx rightly fails with TS2307, writing import { Link } from "../dinou" from src/components/navbar.tsx would climb up to src/ and bind relative links to ROUTE = "/"—even when <Navbar /> is rendered on /blog/hello! Always import from "dinou" inside global folders (src/components/, src/hooks/, src/lib/), and reserve "../dinou" exclusively for route-local subfolders like src/blog/[slug]/components/.
"./dinou" in route entry files (page.tsx, layout.tsx, error.tsx, not_found.tsx, @slot/page.tsx, page_functions.ts, layout_functions.ts) when typing route contracts (PageProps, LayoutProps, etc.) or writing relative links without from."../dinou" only inside a route-local helper subfolder (e.g. src/blog/[slug]/components/) when that component specifically needs relative navigation anchored to its parent route."dinou" everywhere else—shared UI components, helpers, universal hooks (usePathname, useSearchParams, getContext, redirect), and any component that only uses absolute routes—so your components remain portable across folders.Dinou coordinates compilation, route scanning, and TypeScript declarations through a zero-dependency architecture:
src/ Directory
Single-pass scan of src/ across pages, horizontal layouts, @slots, and error boundaries.
generate-route-types
In-memory scanner completes in < 2ms.
routes.d.ts + .dinou/routes
Augments "dinou" & emits contextual "./dinou" modules.
tsconfig.json
Wires include + rootDirs with zero src/ pollution.
Implemented in dinou/core/generate-route-types.js. Pure filesystem parsing without executing user code, importing components, or launching test servers.
_*—ignored by both the router and bundlers) and transparently unwraps route groups ((group)).page.* URLs from intermediate layout.* / layout_functions.* and parallel @slot segments (including @slots inside (group) folders and optional/catch-all slot sub-segments).Generates .dinou/types/routes.d.ts augmenting the core "dinou" module with:
DinouStaticRoutes & DinouDynamicRoutes: Navigable page.* URL unions.DinouNavigableParamsMap: Navigable page.* dynamic patterns powering <Link> & useRouter() autocomplete and params typing.DinouRouteParamsMap: Page & not_found.* param dictionaries.DinouLayoutParamsMap & DinouLayoutSlotsMap: Intermediate & leaf layout params plus auto-inferred @slot props.DinouSlotParamsMap & DinouErrorParamsMap: Parallel @slot and error boundary params.declare module "*.<ext>" entries for custom assetExtensions in dinou.config.ts plus NodeJS.ProcessEnv keys discovered from root .env* files.Types like DinouRouter.Register, DinouRoutePattern, DinouLayoutPattern, DinouSlotPattern, DinouErrorPattern, and ExtractRouteParams<T> are exported to satisfy TypeScript declaration emit rules.
They allow module augmentation to wire seamlessly into the global type contract without polluting your daily application code.
Global route declarations and virtual "./dinou" modules are wired cleanly in your root tsconfig.json (or jsconfig.json) via rootDirs and include:
Keeping .dinou/routes in rootDirs (and out of include) lets TypeScript resolve "./dinou" on demand without polluting IDE auto-import suggestions across unrelated routes.
How Dinou keeps your route typings strictly synchronized across local development, standalone type-checking, and deployment pipelines:
Runs immediately at boot, then arms low-overhead filesystem watchers across src/ and project root config files:
page, page_functions, layout, layout_functions, error, and not_found files (including inside @slot folders), plus changes to dinou.config.{ts,js,mjs}, .env*, and tsconfig.json / jsconfig.json..dinou/types/routes.d.ts (routes, custom assetExtensions, and NodeJS.ProcessEnv keys) and syncs/prunes .dinou/routes/**/dinou.{js,d.ts} in under 2ms.Generates .dinou/types/routes.d.ts and all contextual .dinou/routes/**/dinou.{js,d.ts} modules on demand in milliseconds without launching the dev server or running bundlers:
npm install (since .dinou/ is gitignored).not_found, and @slot types while the dev server is stopped.npm run typegen && npx tsc --noEmit in lightweight PR checks without waiting for a full production build.All bundlers and target pipelines (esbuild, Rollup, Webpack, Node, Bun, Deno, Cloudflare, Netlify) automatically invoke the topology scanner before bundling:
.dinou/types/routes.d.ts and .dinou/routes/**/dinou.{js,d.ts} deterministically as Step 0 of every production build.tsc, npm run build alone will not fail on broken route types. Enforce strict verification in CI/CD (or pre-commit hooks) by running npm run typegen && npx tsc --noEmit (before or independently of the build) or npm run build && npx tsc --noEmit.Existing components without explicit generic parameters continue to work without modification.
You can continue using export default function Page({ params }: any) or generic PageProps during progressive migrations.
If .dinou/types/routes.d.ts has not been generated yet or if a project operates in untyped JavaScript, DinouRoute gracefully falls back to standard string.
Zero breaking changes to existing setups or non-TypeScript workflows.