Private Folders
A folder under app/ whose name starts with an underscore is never routed, so components and helpers can live next to the routes that use them.
text
app/
blog/
_components/
PostCard.tsx # imported by blog/page.tsx, never a URL
page.tsx # ignored: no /blog/_components route
_lib/
format-date.ts
page.tsx # /blogReference
Convention
Any folder whose name begins with _, at any depth: _components, _lib, _utils.
Behavior
- Route discovery skips the folder and everything below it. Nothing inside becomes a page, a
route.tshandler, a layout, or aloading,errorornot-foundfile, even if it has one of those names. - Its modules work like any other module: pages, layouts and route handlers import them normally.
gio routesand.gio/routes.d.tsleave them out.
Examples
Colocate a component
app/blog/_components/PostCard.tsx
import React from 'react';
import { GioLink } from '@gio.js/react';
export function PostCard({ slug, title }: { slug: string; title: string }) {
return (
<GioLink href={`/blog/${slug}`} className="post-card">
{title}
</GioLink>
);
}app/blog/page.tsx
import React from 'react';
import { PostCard } from './_components/PostCard';
const POSTS = [
{ slug: 'hello-world', title: 'Hello, world' },
{ slug: 'routing', title: 'How routing works' },
];
export default function Blog() {
return (
<ul>
{POSTS.map((post) => (
<li key={post.slug}>
<PostCard {...post} />
</li>
))}
</ul>
);
}Good to know
- A folder is enough to keep a file out of routing only for the special names: a
Button.tsxnext to apage.tsxis never a route anyway. Private folders are for grouping, and for keeping a file namedpage.tsxorroute.tsfrom being routed. - No URL segment can start with
_through a folder name. When you need one, answer it with a rewrite to a route without the underscore. - The rule also keeps app routes out of
/_gio, which the server reserves for its own endpoints. - Plain
.cssfiles in a private folder are still served by their path (app/_styles/x.cssat/_styles/x.css) unless[css] enabled = false. See CSS files. - Files in private folders are part of
app/, so in development editing them restarts the worker like any other change there.
Related
Version history
| Version | Changes |
|---|---|
v0.1.0-beta.8 | Introduced: _private folders are never routed. |