Skip to content

Commit 8b4a759

Browse files
committed
docs(router): fix the async resources example in the route resources guide
Only the synchronous part of a route `resources` function runs in an injection context, so the example that created `resource()` after `await import(...)` failed the navigation with NG0203. Capture the injector before the `await` and pass it to the resource.
1 parent a56f203 commit 8b4a759

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎adev/src/content/guide/routing/data-fetching-with-resources.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ The `resources` function can also be `async` and return a `Promise` if you need
9191

9292
```ts
9393
resources: async (ctx) => {
94+
const injector = inject(Injector);
9495
const {fetchUserData} = await import('./user-api');
9596
return {
9697
user: resource({
9798
params: () => ctx.params()['id'],
9899
loader: ({params: id}) => fetchUserData(id),
100+
injector,
99101
}),
100102
};
101103
},

0 commit comments

Comments
 (0)