get pending matches #9488
Replies: 2 comments 1 reply
-
Here is what I have come up with: const usePendingMatches = () => {
const location = useLocation();
const { router } = useContext(DataRouterContext);
const routerState = useContext(DataRouterStateContext);
const nextLocation = routerState?.navigation.location;
const nextPath = useResolvedPath(nextLocation || "");
const nextMatches = useMemo(() => matchRoutes(router.routes, nextPath), [router, nextPath]);
const isMatch = matchPath({ path: location.pathname, end: true }, nextPath.pathname);
if (!isMatch) {
return nextMatches;
}
return []
} |
Beta Was this translation helpful? Give feedback.
-
Yeah, it's a little weird how we've got a handful of hooks for bits of information at a route, and the same information is available for the pending navigation but only in a few places like The obvious but gross answer is to just have a hook for everything but it's the "pending" version.
I'm not pumped about that idea though. Another quick thought is maybe you tell it you want the pending stuff?
Keeps the API surface from exploding, I still don't love it though. Since the idea of "pending" is new, maybe the old APIs aren't the right abstraction anymore? Maybe Or maybe we need a big fat Anybody got ideas for a better API to access this stuff? |
Beta Was this translation helpful? Give feedback.
-
While the router is navigating from one route to another (calling loaders, ect...) I would like to know what (if any) routes are pending.
My exact use case is that while the loaders are being called, I would like to setup the
<link rel="stylesheet" href="..." />
for each pending route so that styles are ready before the new routes mount.Basically, I want a
usePendingMatches()
hook which is the exact same asuseMatches
hook but it only returns "pending" routes.Is it possible to use RR v6.4's public api to create such a hook for myself?
Beta Was this translation helpful? Give feedback.
All reactions