admin管理员组

文章数量:1391999

I would like to open a link in an android app that was built from a SvelteKit project (adapter-static) and capacitor.

I've added the intent-filter in AndroidManifest.xml and the assetlinks.json

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="http" />
    <data android:scheme="https" />

    <data android:host="my-domain" />
</intent-filter>

Clicking a link like will open the app, but only the main page, not the route.

Is this expected and needs to be handled somewhere else? Like in the MainActivity class? Or in the SvelteKit project by using @capacitor/app and App.getLaunchUrl() and/or App.addListener('appUrlOpen', (event) => {...})?

(I tried the latter by adjusting the url in hooks.client.ts and +layout.ts without success and wonder if that's even the way to go...)

I would like to open a link in an android app that was built from a SvelteKit project (adapter-static) and capacitor.

I've added the intent-filter in AndroidManifest.xml and the assetlinks.json

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="http" />
    <data android:scheme="https" />

    <data android:host="my-domain" />
</intent-filter>

Clicking a link like https://my-domain/route will open the app, but only the main page, not the route.

Is this expected and needs to be handled somewhere else? Like in the MainActivity class? Or in the SvelteKit project by using @capacitor/app and App.getLaunchUrl() and/or App.addListener('appUrlOpen', (event) => {...})?

(I tried the latter by adjusting the url in hooks.client.ts and +layout.ts without success and wonder if that's even the way to go...)

Share Improve this question edited Mar 15 at 7:07 Corrl asked Mar 13 at 9:27 CorrlCorrl 7,7811 gold badge19 silver badges45 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

This section in the docs indicates that the routing is done in the frontend framework and only the 'appUrlOpen' event needs to be handled

// +layout.js

import {browser} from '$app/environment';
import {Capacitor} from '@capacitor/core';
import {App as capacitorApp} from '@capacitor/app';

export async function load() {

  const isNativePlatform = Capacitor.isNativePlatform()

  if (browser && isNativePlatform) {
    await capacitorApp.addListener('appUrlOpen', async (event) => {
      const url = event.url
      const urlInstance = new URL(url)
      const navigateTo = urlInstance.pathname + urlInstance.search + urlInstance.hash
      await goto(navigateTo)
    })
  }

  ...

}

本文标签: androidHow to make App Link open on respective route in capacitor appStack Overflow