Naar inhoud springen
Engineering · · 4 min leestijd

Ionic deep linking: de complete configuratiegids

Door Tolinku-team
|
Deep linking in Ionic: volledige configuratiegids

Ionic-apps kunnen Capacitor (aanbevolen) of Cordova als native runtime gebruiken. De configuratie voor deep linking verschilt tussen de twee, maar de URL-afhandeling in JavaScript is hetzelfde. Deze gids behandelt beide manieren.

Voor de Capacitor-specifieke setup, zie Capacitor deep linking: instellen voor Ionic-apps. Voor het cross-platform overzicht, zie cross-platform deep linking-gids voor 2026.

Capacitor is de aanbevolen runtime voor Ionic-apps sinds Ionic 5. Zie voor de volledige Capacitor deep linking-gids voor de uitgebreide installatie. Dit is de samenvatting:

  1. Voeg de Associated Domains-entitlement toe in Xcode (applinks:yourdomain.com).
  2. Voeg Intent filters toe in AndroidManifest.xml.
  3. Zet de AASA- en assetlinks.json-bestanden op je domein.
  4. Gebruik @capacitor/app Verwerk links via het appUrlOpen event van de plugin in JavaScript.
import { App } from '@capacitor/app';

App.addListener('appUrlOpen', (event) => {
  const url = new URL(event.url);
  this.router.navigateByUrl(url.pathname + url.search);
});

Cordova

Als je Ionic-app nog Cordova gebruikt, gebruik dan de ionic-plugin-deeplinks plugin (of cordova-plugin-deeplinks).

Installatie

ionic cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=yourdomain.com

Configuratie

De plugin past de native configuratie automatisch aan:

  • iOS: Voegt de Associated Domains-entitlement toe.
  • Android: Voegt Intent filters toe aan AndroidManifest.xml.

Je moet de AASA- en assetlinks.json-bestanden nog steeds op je domein zetten.

import { Deeplinks } from '@awesome-cordova-plugins/deeplinks/ngx';

constructor(private deeplinks: Deeplinks) {}

initializeDeepLinks() {
  this.deeplinks.route({
    '/products/:productId': 'ProductPage',
    '/offers/:offerId': 'OfferPage',
    '/referral/:referrerId': 'ReferralPage'
  }).subscribe(
    match => {
      console.log('Deep link-match:', match.$route, match.$args);
      // Navigeer op basis van de match
      this.router.navigate([match.$route], {
        queryParams: match.$args
      });
    },
    nomatch => {
      console.warn('Geen deep link-match:', nomatch.$link);
    }
  );
}

Migreren van Cordova naar Capacitor

Bij migratie van Cordova naar Capacitor:

  1. Verwijder ionic-plugin-deeplinks.
  2. Volg de Capacitor deep linking-instellingen.
  3. Vervang de Cordova-plugin's route() API door App.addListener('appUrlOpen', ...).
  4. De native configuratie (entitlements, Intent filters) moet je instellen in je Capacitor-project.

Ionic Angular-integratie

Route-configuratie

Definieer routes die overeenkomen met je deep link-paden:

// app-routing.module.ts
const routes: Routes = [
  { path: '', component: HomePage },
  { path: 'products/:productId', component: ProductPage },
  { path: 'offers/:offerId', component: OfferPage },
  { path: 'referral/:referrerId', component: ReferralPage },
  { path: '**', redirectTo: '' }
];
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Platform } from '@ionic/angular';
import { App } from '@capacitor/app';

@Injectable({ providedIn: 'root' })
export class DeepLinkService {
  constructor(
    private router: Router,
    private platform: Platform
  ) {}

  async initialize() {
    // Stel deep links alleen in op native platforms
    if (!this.platform.is('capacitor')) return;

    // Koude start
    const launchUrl = await App.getLaunchUrl();
    if (launchUrl?.url) {
      this.handleUrl(launchUrl.url);
    }

    // Warme start
    App.addListener('appUrlOpen', (event) => {
      this.handleUrl(event.url);
    });
  }

  private handleUrl(urlString: string) {
    try {
      const url = new URL(urlString);
      const path = url.pathname;

      // Gebruik de Angular router om te navigeren
      this.router.navigateByUrl(path + url.search).catch(err => {
        console.error('Navigatie mislukt:', err);
        this.router.navigate(['/']);
      });
    } catch (e) {
      console.error('Ongeldige deep link-URL:', urlString);
    }
  }
}

Initialiseren in de App-component

// app.component.ts
import { Component, OnInit } from '@angular/core';
import { DeepLinkService } from './services/deep-link.service';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit {
  constructor(private deepLinkService: DeepLinkService) {}

  ngOnInit() {
    this.deepLinkService.initialize();
  }
}

Ionic React-integratie

// App.tsx
import { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { App as CapApp } from '@capacitor/app';
import { isPlatform } from '@ionic/react';

const AppDeepLinks: React.FC = () => {
  const history = useHistory();

  useEffect(() => {
    if (!isPlatform('capacitor')) return;

    // Koude start
    CapApp.getLaunchUrl().then(result => {
      if (result?.url) {
        const url = new URL(result.url);
        history.push(url.pathname + url.search);
      }
    });

    // Warme start
    const listener = CapApp.addListener('appUrlOpen', event => {
      const url = new URL(event.url);
      history.push(url.pathname + url.search);
    });

    return () => { listener.then(l => l.remove()); };
  }, [history]);

  return null;
};

Ionic Vue-integratie

// composables/useDeepLinks.ts
import { onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';
import { App } from '@capacitor/app';
import { isPlatform } from '@ionic/vue';

export function useDeepLinks() {
  const router = useRouter();
  let listener: any;

  onMounted(async () => {
    if (!isPlatform('capacitor')) return;

    // Koude start
    const launchUrl = await App.getLaunchUrl();
    if (launchUrl?.url) {
      const url = new URL(launchUrl.url);
      router.push(url.pathname + url.search);
    }

    // Warme start
    listener = await App.addListener('appUrlOpen', (event) => {
      const url = new URL(event.url);
      router.push(url.pathname + url.search);
    });
  });

  onUnmounted(() => {
    listener?.remove();
  });
}

Testen

Browser (ontwikkeling)

Navigeer rechtstreeks naar deep link-paden:

http://localhost:8100/products/abc123

Native (iOS-simulator)

xcrun simctl openurl booted "https://yourdomain.com/products/abc123"

Native (Android)

adb shell am start -a android.intent.action.VIEW \
  -d "https://yourdomain.com/products/abc123" \
  -c android.intent.category.BROWSABLE

Veelvoorkomende problemen

Probleem Oorzaak Oplossing
Deep links werken op Android maar niet op iOS Probleem met het AASA-bestand of een ontbrekende entitlement Controleer AASA en Associated Domains
Route niet gevonden na deep link Angular-, React- of Vue-router matcht niet Controleer of de routepaden overeenkomen met de deep link-paden
Werkt in de browser maar niet op het apparaat Native configuratie ontbreekt Controleer de entitlements (iOS) en Intent filters (Android)
Bij een koude start toont de app eerst de startpagina en navigeert daarna Timingprobleem bij navigatie Verwerk de launch URL vóór de eerste render

Tolinku voor Ionic-apps

Tolinku Tolinku biedt hosting voor de AASA- en assetlinks.json-bestanden, zodat je de verificatiebestanden niet zelf hoeft te beheren. De Tolinku web SDK werkt met Ionic-apps voor smart banners.

Voor deep linking in React Native, zie React Native deep linking: complete installatiehandleiding. Voor de volledige gids, zie cross-platform deep linking-gids voor 2026.

Ontvang deep linking-tips in je inbox

Eén e-mail per week. Geen spam.

Klaar om deep linking aan je app toe te voegen?

Stel Universal Links, App Links, deferred deep linking en analytics in enkele minuten in. Gratis om te beginnen.