From c1be4f6e6e5d299cafc70880504309ea03c71e24 Mon Sep 17 00:00:00 2001 From: ImJustChew Date: Tue, 16 Apr 2024 00:42:16 +0800 Subject: [PATCH] added apple app site assoc --- public/.well-known/apple-app-site-association | 12 ++++++++++ src/app/[lang]/layout.tsx | 2 ++ src/components/AppUrlListener.tsx | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 public/.well-known/apple-app-site-association create mode 100644 src/components/AppUrlListener.tsx diff --git a/public/.well-known/apple-app-site-association b/public/.well-known/apple-app-site-association new file mode 100644 index 00000000..26d26465 --- /dev/null +++ b/public/.well-known/apple-app-site-association @@ -0,0 +1,12 @@ +{ + "applinks": { + "apps": [], + "details": [ + { + "appID": "87D52NF2QC.com.nthumods.courseweb", + "paths": ["*"] + } + ] + } +} + diff --git a/src/app/[lang]/layout.tsx b/src/app/[lang]/layout.tsx index c0f6df76..dfdc6672 100644 --- a/src/app/[lang]/layout.tsx +++ b/src/app/[lang]/layout.tsx @@ -15,6 +15,7 @@ import { Toaster } from '@/components/ui/toaster'; import ReactQuery from '@/components/ReactQuery'; import './globals.css' +import AppUrlListener from '@/components/AppUrlListener'; export const metadata: Metadata = { title: { @@ -120,6 +121,7 @@ export default function RootLayout({ {children} + diff --git a/src/components/AppUrlListener.tsx b/src/components/AppUrlListener.tsx new file mode 100644 index 00000000..779e09ac --- /dev/null +++ b/src/components/AppUrlListener.tsx @@ -0,0 +1,24 @@ +'use client'; +import { useRouter } from "next/navigation"; +import { useEffect } from "react"; +import { App, URLOpenListenerEvent } from '@capacitor/app'; + +const AppUrlListener: React.FC = () => { + const router = useRouter(); + useEffect(() => { + App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => { + // Example url: https://beerswift.app/tabs/tab2 + // slug = /tabs/tab2 + const slug = event.url.split('.app').pop(); + if (slug) { + router.push(slug); + } + }); + }, []); + + return <>; + }; + + export default AppUrlListener; + + \ No newline at end of file