fix: add conditional for getCustomViewByRoute
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user