The generated helpers for App Router routes follow a specific pattern to ensure type safety for both the path and the query parameters.
For a route with dynamic segments, the helper is generated as a function. The signature depends on whether a Query type was detected in the source file:
- With Query Type: If
pathpida detects a query type in the page.tsx file, the helper accepts a url object containing both the query and an optional hash. - Without Query Type: The helper accepts the dynamic segments directly as arguments and returns an object containing the
pathname, query, hash, and path.
Dynamic Segment Types:
[slug]: Generates a string | number type.[...slug]: Generates a string[] type.[[...slug]]: Generates an optional parameter.
Returned Object Shape:
Every helper returns an object with:
pathname: The static string representation of the route.query: An object containing the parsed query parameters.hash: The URL hash.path: A template string (e.g., /${slug}) used for actual navigation.
// Example of what the generated code looks like for a route like /blog/[slug]
$blog_slug: (slug: string) => ({
pathname: '/blog/[slug]' as const,
query: { ... },
hash: url.hash,
path: `/blog/${slug}`
});
// Example for a route with a Query type
$blog_slug: (url: { query: BlogQuery, hash?: string }) => ({
pathname: '/blog/[slug]' as const,
query: { ...url.query },
hash: url.hash,
path: `/blog/${slug}`
});