diff --git a/.changeset/wicked-chicken-attack.md b/.changeset/wicked-chicken-attack.md new file mode 100644 index 00000000..5d1b580d --- /dev/null +++ b/.changeset/wicked-chicken-attack.md @@ -0,0 +1,5 @@ +--- +"@premieroctet/next-admin": minor +--- + +feat: redirect to first resource if dashboard doesnt exist diff --git a/packages/next-admin/src/components/Dashboard.tsx b/packages/next-admin/src/components/Dashboard.tsx index 21e07243..e416bc63 100644 --- a/packages/next-admin/src/components/Dashboard.tsx +++ b/packages/next-admin/src/components/Dashboard.tsx @@ -1,7 +1,21 @@ -export type DashboardProps = {}; +"use client"; +import { useConfig } from "../context/ConfigContext"; +import { useRouterInternal } from "../hooks/useRouterInternal"; +import { ModelName } from "../types"; -const Dashboard = ({}: DashboardProps) => { - return
Dashboard
; +export type DashboardProps = { + resources: ModelName[]; +}; + +const Dashboard = ({ resources }: DashboardProps) => { + const { basePath } = useConfig(); + const { router } = useRouterInternal(); + + router.replace({ + pathname: `${basePath}/${resources[0]}`, + }); + + return null; }; export default Dashboard; diff --git a/packages/next-admin/src/components/NextAdmin.tsx b/packages/next-admin/src/components/NextAdmin.tsx index d1dd85c0..f289b269 100644 --- a/packages/next-admin/src/components/NextAdmin.tsx +++ b/packages/next-admin/src/components/NextAdmin.tsx @@ -95,7 +95,7 @@ export function NextAdmin({ if (resources) { if (dashboard && typeof dashboard === "function") return dashboard(); - return dashboard || ; + return dashboard || ; } };