#How can I get route context in on*?

10 messages · Page 1 of 1 (latest)

strong marten
#

I see that route context is not available on the on* route methods. Is it only intended for the loaders? I'd like to use route context as my dependency injection mechanism for route behaviors like onCatch

quaint saffron
#

you get the match passed in which has the context, right?

strong marten
#

I was looking at onError and onCatch. I see that others have the RouteMatch

quaint saffron
#

yeah those dont get it

#

there is no guarantuee that context is available at this point

#

could maybe be passed in as optional?

strong marten
#

there is no guarantuee that context is available at this point
You mean in the sense that some code in tanstack router could fail before getting to user-provided code such that the context isn't available?

#

Alternatively, thinking about what could be done to do dependency injection for route construction if onCatch / onError do not receive the route context. I could use a singleton but then I'd have to do module mocking in tests, which I'd like to avoid

quaint saffron
#

You mean in the sense that some code in tanstack router could fail before getting to user-provided code such that the context isn't available?
no it could be that your beforeLoad throws for example and then route context is not (fully) availabl