UNPKG

vite-plugin-remix-routes

Version:
19 lines (18 loc) 469 B
// lib/client/eager-loader.ts import { useEffect } from "react"; import { matchRoutes, useLocation } from "react-router-dom"; function EagerLoader({ routes }) { const location = useLocation(); useEffect(() => { const matches = matchRoutes(routes, location) || []; matches.forEach((match) => { const route = match.route; if (route.importPromise) route.importPromise(); }); }, [location]); return null; } export { EagerLoader };