quilt icon indicating copy to clipboard operation
quilt copied to clipboard

Add `load()` method to routes

Open lemonmade opened this issue 2 years ago • 2 comments

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} />;
  },
}];

lemonmade avatar Mar 19 '23 21:03 lemonmade

The tricky bit here will be adding the necessary types to support data and context.

lemonmade avatar Jun 11 '24 01:06 lemonmade

Maybe make the first argument to load something like a Request object that represents the navigation request.

lemonmade avatar Jun 11 '24 01:06 lemonmade