#Logging current route/page being loaded
1 messages ยท Page 1 of 1 (latest)
Hello ๐
You can try to use let location = useLocation(); in your root.tsx.
https://reactrouter.com/en/6.15.0/hooks/use-location
You can use remix utils, which has a series of global loader contexts you can listen to
nice thanks for the suggestion. I gave it a try and am able to log the current pathname. what do you mean by remix utils?
is this from npm i remix-utils?
Yes. Maybe I'm missing something but I found nothing about path in remix utils ๐ฆ
yeah I'm still looking at the docs as well and can't seem to find anything. that might help here. I could be missing it
Does useLocation works for you?
The other way is to have a loader on root.tsx:
export function loader({ request }: DataFunctionArgs) {
console.log(new URL(request.url).pathname);
return null;
}
But It will work only on the first document load.
root loader is not rerun on navigate.
yeah, thank you. using useLocation().pathname seems to be working just fine. instead of logging 'page_loaded' in my components I moved it into the App component in root.tsx to log 'loading route ${pathname}'
its important that it logs on every route change and not just on first document load
It is the best place for that ๐
thank you very much for your help ๐
I wasn't referring to the path name, but the loading state globally,
https://github.com/sergiodxa/remix-utils#useglobaltransitionstates
Normally for the route of the current page in my root loader I return the URL like Raphael is suggesting
but to determine if they're all finished loading/updating you check the global states on the client side