From b0d3cc2346a47f5108f459ae7653a5a1b70fc7be Mon Sep 17 00:00:00 2001 From: abdullaev Date: Thu, 12 Oct 2023 13:46:48 +0500 Subject: [PATCH] feat: createRoutesView otherwise param can have layout --- src/create-routes-view.tsx | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/create-routes-view.tsx b/src/create-routes-view.tsx index aae33da..ff3cac8 100644 --- a/src/create-routes-view.tsx +++ b/src/create-routes-view.tsx @@ -11,7 +11,7 @@ export interface RouteRecord { export interface RoutesViewConfig { routes: RouteRecord[]; - otherwise?: React.ComponentType; + otherwise?: React.ComponentType | Omit, 'route'>; } export function createRoutesView(config: Config) { @@ -29,9 +29,9 @@ export function createRoutesView(config: Config if (route.layout) { const Layout = route.layout; return ( - - - + + + ); } @@ -40,11 +40,28 @@ export function createRoutesView(config: Config } if (mergedConfig.otherwise) { - const Otherwise = mergedConfig.otherwise; + const otherwise = mergedConfig.otherwise; + if (isComponent(otherwise)) { + const Otherwise = otherwise; + return ; + } - return ; + const View = otherwise.view; + if (otherwise.layout) { + const Layout = otherwise.layout; + return ( + + + + ) + } + return } return null; }; } + +function isComponent(obj: unknown): obj is React.ComponentType { + return typeof obj === 'function'; +}