Skip to content

Add loaders to routes with a chainable addLoader - #811

Open
pleek91 wants to merge 2 commits into
drop-dead-navigation-guardfrom
add-loader
Open

Add loaders to routes with a chainable addLoader#811
pleek91 wants to merge 2 commits into
drop-dead-navigation-guardfrom
add-loader

Conversation

@pleek91

@pleek91 pleek91 commented Aug 3, 2026

Copy link
Copy Markdown
Member

Description

Third step of #805, stacked on #809.

Loaders are a route's data, declared the way views are declared but with no component attached and no hold on rendering:

createRoute({ name: 'user', path: '/user/[id]' })
  .addView(UserView, { props: (route) => ({ id: route.params.id }) })
  .addLoader(async (route) => api.getUser(route.params.id))
  .addLoader(async (route) => api.getPosts(route.params.id), { name: 'posts' })

They are stored per match, alongside views, so a route's data can be derived from its matches the same way its views already are — including an ancestor's loaders, which a child should be able to use as its own.

Both chainable methods now rebuild through withRouteMethods. Previously addView re-attached only itself, so chaining a view after a loader would have dropped addLoader from the route — the two have to be re-attached together, and neither file needs to know about the other for that.

A loader name an ancestor already uses throws LoaderNameConflict. A route's data combines the loaders of every match, so the same name in two places would be ambiguous rather than an override — unlike adding a loader the route itself already has, which replaces it, as views do.

Nothing runs a loader yet. What this proves is declaration: names, prefetch configs, immutability, chaining in both orders, and ancestor conflicts.

@pleek91
pleek91 changed the base branch from loaders-on-matches to drop-dead-navigation-guard August 3, 2026 17:57
@pleek91 pleek91 changed the title Add a chainable addLoader to routes Add loaders to routes with a chainable addLoader Aug 3, 2026
pleek91 added 2 commits August 6, 2026 09:18
Loaders are stored per match alongside views, so a route's data can be
derived from its matches the same way its views are.
Loaders are declared the same way views are, and both methods now rebuild
through withRouteMethods so chaining one never drops the other. A loader
name an ancestor already uses throws, since a route's data combines the
loaders of every match.
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