// router의 동작을 컨트롤 하기 위한 code injection.
// 아래의 함수를 WebView 컴포넌트의
// injectedJavaScript, injectedJavaScriptBeforeContentLoaded
// props에 넘겨주어야 합니다.
const injectedJavaScript = `
(function() {
const overrideRouterPush = function() {
window.isNativeApp = true;
const originalPush = window.next.router.push;
window.next.router.push = function(url, as, options) {
const shouldInterceptPush = ['/buy', '/artwork'].some(pattern =>
url?.includes(pattern)
);
if (shouldInterceptPush) {
window.ReactNativeWebView.postMessage(
JSON.stringify({
event: 'routerPush',
data: {
url: url,
},
})
);
return;
}
originalPush.call(this, url, as, options);
};
};
window.onload = overrideRouterPush;
})();
`;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter