Skip to content

feat: add defineRoute and defineRoutes declarative helpers - #17

Merged
olliethedev merged 2 commits into
mainfrom
feat/define-routes
Jul 3, 2026
Merged

feat: add defineRoute and defineRoutes declarative helpers#17
olliethedev merged 2 commits into
mainfrom
feat/define-routes

Conversation

@olliethedev

Copy link
Copy Markdown
Collaborator

Summary

  • Adds defineRoute(path, def, options?, routeMeta?): a declarative variant of createRoute that removes the per-route handler-closure boilerplate. page/loading/error components receive the route context (params, query) as props; loader/meta/extra receive it as their first argument, with extra caller args (e.g. AbortSignal) forwarded after it.
  • Adds defineRoutes(routes, { pages? }): groups routes for createRouter with optional per-key page component overrides. Overrides on defineRoute routes are rebuilt so the replacement component still receives the route context; plain createRoute routes get their PageComponent swapped as-is.
  • Adds react as a peer dependency (the helpers use createElement to bind context into components); bumps version to 1.3.0.
  • README section documenting the new helpers.

Motivation: consumers like @btst/stack currently repeat a handler closure per route wiring PageComponent override lookup, loader, and meta (~6x per plugin). These helpers collapse that to one declaration per route while staying fully compatible with createRoute/createRouter.

Test plan

  • 19 new unit tests in src/__tests__/define.test.ts: context injection into page/loading/error props, render-time prop merging, loader/meta/extra binding (sync + async + extra args), query validation passthrough (pass and fail), route-level metadata, createRouter interop (routeKey, params), page overrides for both defineRoute and plain createRoute routes
  • pnpm build, pnpm lint, pnpm typecheck, pnpm test -- --run all pass locally (79/79 tests)

Made with Cursor

olliethedev and others added 2 commits July 3, 2026 15:18
Removes the handler-closure boilerplate consumers repeat per route: page,
loading, and error components receive the route context (params, query) as
props, and loader/meta/extra receive it as their first argument. defineRoutes
groups routes and supports per-key page component overrides while preserving
loaders, meta, extra, options, and route metadata.

Adds react as a peer dependency (the helpers use createElement to bind
context into components).

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@olliethedev
olliethedev merged commit cc2adb8 into main Jul 3, 2026
2 checks passed
@olliethedev
olliethedev deleted the feat/define-routes branch July 3, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant