Skip to content

useMatches hook not returning data from my route handle #9710

Closed Answered by brophdawg11
preacher2041 asked this question in Q&A
Discussion options

You must be logged in to vote

Yep, you've identified the underlying issue :). Descendant routes are not known to useMatches (docs) since matching in a RouterProvider is done before rendering, and descendant <Routes> are not discovered until rendering.

The recommendation would be to lift your route definitions up to the initial route tree and then use code splitting to lazily load the loaders/actions/elements for those routes. There's a good community article on this here.

Then you can check for protected routes in your loaders. For now, you'll want to check in each loader until this proposal gets implemented and then you will be able to check for your protected routes in a single parent beforeLoader-type function.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@preacher2041
Comment options

Answer selected by preacher2041
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants