Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Refactor customRoutes.tsx and ProjectConfigInterface.ts to include co…
Browse files Browse the repository at this point in the history
…mponent props (#10359)

Co-authored-by: Hanzla Mateen <[email protected]>
  • Loading branch information
hurairahmateen and hanzlamateen authored Jun 11, 2024
1 parent 5c7c3c6 commit 64c65ea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/route/customRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const CustomRoutes = ({ customRoutes }) => {
<Suspense fallback={<LoadingCircle message={t('common:loader.loadingCustom')} />}>
<Routes>
{matchedRoutes.map((route, i) => {
const { route: r, component, props: p } = route
const { route: r, component, props: p, componentProps } = route
const Element = component as any
return (
<Route
key={`custom-route-${i}`}
path={r.split('/')[1] === '' ? `${r}*` : `${r}/*`}
element={<Element />}
element={<Element {...componentProps} />}
{...p}
/>
)
Expand Down
3 changes: 3 additions & 0 deletions packages/projects/ProjectConfigInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export interface ProjectConfigInterface {
[x: string]: any
exact?: boolean
}
componentProps?: {
[x: string]: any
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/projects/loadRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { loadConfigForProject } from './loadConfigForProject'
interface RouteData {
component: ReturnType<typeof lazy>
props: any
componentProps: any
}

export const loadRoute = async (project: string, route: string): Promise<RouteData | null> => {
Expand All @@ -38,7 +39,8 @@ export const loadRoute = async (project: string, route: string): Promise<RouteDa
if (!projectConfig.routes || !projectConfig.routes[route]) return null
return {
component: lazy(projectConfig.routes[route].component),
props: projectConfig.routes![route].props
props: projectConfig.routes![route].props,
componentProps: projectConfig.routes![route].componentProps
}
} catch (e) {
console.log(`Failed to import route ${route} for project ${project} with reason ${e}`)
Expand Down

0 comments on commit 64c65ea

Please sign in to comment.