quilt
quilt copied to clipboard
Add `load()` method to routes
const routes = [{
match: /\d+/,
async load({matched, signal, source}, {graphql}) {
if (source === 'preload') console.log('Preloading...');
const queryPromise = graphql.query(
`query ResourceDetails($id: String!) { resource(id: $id) { name } }`,
{variables: {id: matched}},
);
const [result] = await Promise.all([
queryPromise,
ResourceDetails.load(),
]);
return result;
},
render({matched, data}) {
return <ResourceDetails id={matched} />;
},
}];
The tricky bit here will be adding the necessary types to support data and context.
Maybe make the first argument to load something like a Request object that represents the navigation request.