paths()
paths() tells StatikAPI which concrete routes to emit for a dynamic or catch-all file.
It is used by:
- dynamic routes like
users/[id].js - catch-all routes like
docs/[...slug].js
Dynamic route example
// src-api/users/[id].js
export async function paths() {
return ['1', '2', '3'];
}
Each string becomes one emitted route:
/users/1/users/2/users/3
Catch-all route example
// src-api/docs/[...slug].js
export async function paths() {
return [['guide'], ['api', 'intro']];
}
Each string array becomes one emitted route:
/docs/guide/docs/api/intro
Rules
Dynamic routes
paths() must return:
- an array of strings
Catch-all routes
paths() must return:
- an array of string arrays
General validation
Returned path segments must be valid route segments:
- no empty strings
- no
/inside a segment - no non-string values
If paths() returns invalid data, the build fails with an explicit error.
Missing paths()
If a dynamic or catch-all route does not export paths():
- that route is skipped
- the whole build does not fail only because
paths()is missing
This is useful during gradual development, but for a real route you usually want paths() in place.
Interaction with listIndex
If the same route also uses:
export const config = { listIndex: true };
then:
paths()controls the concrete emitted routeslistIndexcontrols whether a parent collection route is also emitted from those results