android - How to make App Link open on respective route in capacitor app? - Stack Overflow

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

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)
    })
  }

  ...

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744711154a4589350.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信