Skip to content
Discussion options

You must be logged in to vote

If it's not async, in your root route component you can use useLocation().pathname to know the current URL pathname and derive the className from that.

If you need to do it async (e.g. fetch an API or query a DB) you will need to do it in the loader, you could either add shouldRevalidate to the root route and always return true so it always runs again or you can return the className from any other loader and use useMatches to grab the data returned by any loader and pick somehow which value to use (e.g. always use the last route defining a className).

let matches = useMatches()
let { className } = matches.map(match => match.data).reverse().first(data => data?.className)

Something like tha…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dchenk
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