From e301393f334efe9cc7a3f27a00a2c060bfa14333 Mon Sep 17 00:00:00 2001 From: Paul Popus Date: Fri, 15 Mar 2024 10:26:46 -0300 Subject: [PATCH] fix: add conditional for getCustomViewByRoute --- .../src/views/Root/getCustomViewByRoute.tsx | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/next/src/views/Root/getCustomViewByRoute.tsx b/packages/next/src/views/Root/getCustomViewByRoute.tsx index 61145c69ea..4255502824 100644 --- a/packages/next/src/views/Root/getCustomViewByRoute.tsx +++ b/packages/next/src/views/Root/getCustomViewByRoute.tsx @@ -18,26 +18,29 @@ export const getCustomViewByRoute = ({ const currentRoute = currentRouteWithAdmin.replace(adminRoute, '') - const foundViewConfig = Object.entries(views).find(([, view]) => { - if (typeof view === 'object') { - const { exact, path: viewPath, sensitive, strict } = view + const foundViewConfig = + views && + typeof views === 'object' && + Object.entries(views).find(([, view]) => { + if (typeof view === 'object') { + const { exact, path: viewPath, sensitive, strict } = view - const keys = [] + const keys = [] - // run the view path through `pathToRegexp` to resolve any dynamic segments - // i.e. `/admin/custom-view/:id` -> `/admin/custom-view/123` - const regex = pathToRegexp(viewPath, keys, { - sensitive, - strict, - }) + // run the view path through `pathToRegexp` to resolve any dynamic segments + // i.e. `/admin/custom-view/:id` -> `/admin/custom-view/123` + const regex = pathToRegexp(viewPath, keys, { + sensitive, + strict, + }) - const match = regex.exec(currentRoute) - const viewRoute = match?.[0] || viewPath + const match = regex.exec(currentRoute) + const viewRoute = match?.[0] || viewPath - if (exact) return currentRoute === viewRoute - if (!exact) return viewRoute.startsWith(currentRoute) - } - })?.[1] + if (exact) return currentRoute === viewRoute + if (!exact) return viewRoute.startsWith(currentRoute) + } + })?.[1] return typeof foundViewConfig === 'object' ? foundViewConfig.Component : null }