Is it an ok usage pattern to do api calls inside the beforeload of a route? #7288
-
|
There are some scenarios where we need to know beforehand the state of some server data before we can even render the page to the user; we may need to redirect them somewhere else based on what that data is. Or, for example, in order to show a specific item's title as part of the breadcrumbs, we need that server information in order to include it in the breadcrumb context we return in the I want to make sure there are no gotchas or some better way to do it inversely, is it ok to throw a redirect inside the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
both is "ok". you can call an API in you just need to understand the consequences: when you navigate to /foo/bar/baz, this would for example match 3 nested routes (
|
Beta Was this translation helpful? Give feedback.
both is "ok". you can call an API in
beforeLoadand you can also throw aredirectin aloader.you just need to understand the consequences:
when you navigate to /foo/bar/baz, this would for example match 3 nested routes (
foo,bar,baz), then following happens:beforeLoadof all those routes run serially, so firstfoo'sbeforeLoad, thenbar'sbeforeLoad,baz'sbeforeLoadloaderof all those routes run in parallel. so if one loader throws aredirect, the other loaders would still execute!