Get nested layouts for a current route
npm install @guyathomas/layout-for-pathreact-router style API for wrapping your application in layouts, depending on the current route.layout element, and can serve as matching a prefix for child routes/, param routes /:uuid, and exact match routes /driver/name are supportedjavascriptimport { useRouter } from "next/router";
import LayoutForPage, { LayoutSpec } from "@guyathomas/layout-for-path";
/ ... Layout Imports Omitted ... /
const layoutSpec: LayoutSpec[] = [
{
pattern: "/dashboard", // my-app.com/dashboard/* would be wrapped in this
layout: ({ children }) => (
{children}
)
},
{
pattern: "/*", // Everything that doesn't match my-app.com/dashboard will render {children}
layout: MainLayout,
children: [
{
pattern: "/", // my-app.com/ will render {children}
layout: HomePageLayout,
},
{
pattern: "/browse/*", // my-app.com/browse/some-route will render {children}
layout: BrowseLayout,
},
],
},
];
const AppLayout: React.FC = ({ children }) => {
const router = useRouter();
return (
{children}
);
};
``