Skip to content

Commit ab3abcb

Browse files
committed
feat: add openExternalLink utility to handle external links in webview and browsers
- Introduced a new utility function `openExternalLink` that detects the environment (webview or regular browser) and opens external links accordingly. - Updated `tsconfig.node.tsbuildinfo` to include the new utility file.
1 parent a9e0c2e commit ab3abcb

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/router/useRouter.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { useNavigate } from 'react-router-dom';
22
import { StockCountryKey } from '@ts/StockCountry';
33
import { TermKey } from '@ts/Term';
4-
import { useIsMobile } from '@hooks/useIsMobile';
4+
import { openExternalLink } from '@utils/openExternalLink';
55
import { webPath } from '.';
66

77
const useRouter = () => {
88
const navigate = useNavigate();
9-
const isMobile = useIsMobile();
109

1110
const navToBack = () => navigate(-1);
1211

@@ -35,24 +34,19 @@ const useRouter = () => {
3534
const navToTerm = (termKey: TermKey) => navigate(`${webPath.term}?term=${termKey}`);
3635

3736
const openBusinessProposal = () => {
38-
window.location.href = 'mailto:humanzipyo2024@gmail.com?cc=anyany3151@naver.com';
37+
openExternalLink('mailto:humanzipyo2024@gmail.com?cc=anyany3151@naver.com');
3938
};
4039
const openServiceCenter = () => {
41-
window.location.href = 'https://forms.gle/eus2xRNHGxbSBaAK9';
40+
openExternalLink('https://forms.gle/eus2xRNHGxbSBaAK9');
4241
};
4342
const openInstagram = () => {
44-
window.location.href = 'https://www.instagram.com/humanzipyo/';
43+
openExternalLink('https://www.instagram.com/humanzipyo/');
4544
};
4645
const openLinkedIn = () => {
47-
if (isMobile) {
48-
window.location.href = 'linkedin://profile/humanzipyo';
49-
return;
50-
}
51-
52-
window.location.href = 'https://www.linkedin.com/company/humanzipyo';
46+
openExternalLink('https://www.linkedin.com/company/humanzipyo');
5347
};
5448
const openThreads = () => {
55-
window.location.href = 'https://www.threads.net/@humanzipyo';
49+
openExternalLink('https://www.threads.net/@humanzipyo');
5650
};
5751

5852
return {

src/utils/openExternalLink.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { MESSAGE_TYPES } from '../config/webview';
2+
import { detectWebView } from './Detector';
3+
4+
/**
5+
* 외부 링크를 시스템 브라우저로 엽니다.
6+
* - 웹뷰 환경: 네이티브 앱에 메시지를 전송하여 시스템 브라우저 실행
7+
* - 일반 브라우저: 새 탭에서 링크 열기
8+
*/
9+
export const openExternalLink = (url: string): void => {
10+
const isWebView = detectWebView();
11+
12+
if (isWebView && (window as any).ReactNativeWebView) {
13+
// WebView 환경: 네이티브 앱으로 메시지 전송
14+
(window as any).ReactNativeWebView.postMessage(
15+
JSON.stringify({
16+
type: MESSAGE_TYPES.OPEN_EXTERNAL_BROWSER,
17+
url,
18+
}),
19+
);
20+
} else {
21+
// 일반 브라우저: 새 탭에서 열기
22+
window.open(url, '_blank');
23+
}
24+
};

0 commit comments

Comments
 (0)