Skip to content

Commit e2e7830

Browse files
committed
feat: sitemap로 외부 링크를 갈 수 있도록 수정
1 parent 813e716 commit e2e7830

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

apps/pyconkr/src/components/layout/Header/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ const Header: React.FC = () => {
7272
{Object.values(siteMapNode.children)
7373
.filter((s) => !s.hide)
7474
.map((r) => (
75-
<Link key={r.id} to={r.route_code} onClick={resetDepths}>
75+
<Link
76+
key={r.id}
77+
onClick={resetDepths}
78+
target={R.isString(r.external_link) ? "_blank" : undefined}
79+
rel={R.isString(r.external_link) ? "noopener noreferrer" : undefined}
80+
to={r.external_link || r.route_code}
81+
>
7682
<Button key={r.id} onMouseEnter={() => setDepth1(r)} sx={{ minWidth: 0, textTransform: "none" }}>
7783
{r.name}
7884
</Button>
@@ -100,7 +106,9 @@ const Header: React.FC = () => {
100106
onMouseEnter={() => setDepth2(r)}
101107
// 하위 depth가 있는 경우, 하위 depth를 선택할 수 있도록 유지하기 위해 depth2도 유지합니다.
102108
onMouseLeave={() => R.isEmpty(navState.depth2?.children ?? {}) && setDepth2(undefined)}
103-
to={getDepth2Route(r.route_code)}
109+
target={R.isString(r.external_link) ? "_blank" : undefined}
110+
rel={R.isString(r.external_link) ? "noopener noreferrer" : undefined}
111+
to={r.external_link || getDepth2Route(r.route_code)}
104112
/>
105113
))}
106114
</Stack>
@@ -120,7 +128,9 @@ const Header: React.FC = () => {
120128
onClick={resetDepths}
121129
onMouseEnter={() => setDepth3(r)}
122130
onMouseLeave={() => setDepth3(undefined)}
123-
to={getDepth3Route(r?.route_code)}
131+
target={R.isString(r.external_link) ? "_blank" : undefined}
132+
rel={R.isString(r.external_link) ? "noopener noreferrer" : undefined}
133+
to={r.external_link || getDepth3Route(r?.route_code)}
124134
/>
125135
))}
126136
</Stack>

apps/pyconkr/src/components/pages/dynamic_route.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ export const RouteRenderer: React.FC = ErrorBoundary.with(
135135
Suspense.with({ fallback: <CenteredLoadingPage /> }, () => {
136136
const { siteMapNode, currentSiteMapDepth } = useAppContext();
137137
const routeInfo = !R.isEmpty(currentSiteMapDepth) && currentSiteMapDepth[currentSiteMapDepth.length - 1];
138-
return !(siteMapNode && routeInfo) ? <WaitedCenteredLoadingPage /> : <PageRenderer id={routeInfo.page} />;
138+
139+
if (!(siteMapNode && routeInfo)) return <WaitedCenteredLoadingPage />;
140+
if (R.isString(routeInfo.page)) return <PageRenderer id={routeInfo.page} />;
141+
if (R.isString(routeInfo.external_link)) window.location.replace(routeInfo.external_link);
142+
return <PageNotFound />;
139143
})
140144
);
141145

packages/common/src/schemas/backendAPI.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ namespace BackendAPISchemas {
2020
name: string;
2121
order: number;
2222
parent_sitemap: string | null;
23-
page: string;
2423
hide: boolean;
24+
page: string | null;
25+
external_link: string | null;
2526
};
2627

2728
export type NestedSiteMapSchema = {
2829
id: string;
2930
route_code: string;
3031
name: string;
3132
order: number;
32-
page: string;
3333
hide: boolean;
3434
parent_sitemap: string | null;
3535
children: NestedSiteMapSchema[];
36+
page: string | null;
37+
external_link: string | null;
3638
};
3739

3840
export type SectionSchema = {

packages/common/src/schemas/backendAdminAPI.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ namespace BackendAdminAPISchemas {
6363
name_en: string;
6464
order: number;
6565
parent_sitemap: string | null;
66-
page: string;
6766
hide: boolean;
67+
page: string | null;
68+
external_link: string | null;
6869
};
6970

7071
export type NestedSiteMapSchema = {
@@ -74,9 +75,10 @@ namespace BackendAdminAPISchemas {
7475
name_en: string;
7576
order: number;
7677
parent_sitemap: string | null;
77-
page: string;
7878
hide: boolean;
7979
children: NestedSiteMapSchema[];
80+
page: string | null;
81+
external_link: string | null;
8082
};
8183

8284
export type PageSectionBulkUpdateSchema = PageSectionSchema | Omit<PageSectionSchema, "id">;

packages/common/src/utils/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type GFlatSiteMap = {
55
route_code: string;
66
order: number;
77
parent_sitemap: string | null;
8-
page: string;
98
hide: boolean;
109
};
1110
type GNestedSiteMap<T = GFlatSiteMap> = T & { children: GNestedSiteMap<T>[] };

0 commit comments

Comments
 (0)