vite-plugin-remix-routes
Version:
Use Remix routing in your Vite project
19 lines (18 loc) • 469 B
JavaScript
// 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
};