Deep link-afhandeling vereist platformspecifieke startpunten (Universal Links op iOS, App Links op Android, URL-routering op het web), maar de eigenlijke routinglogica, het deel dat bepaalt "deze URL hoort bij dit scherm met deze parameters", kan gedeeld worden. Dit artikel beschrijft patronen om linkafhandelingscode één keer te schrijven en per platform aan te passen.
Voor het volledige overzicht van cross-platform, zie cross-platform deep linking-gids voor 2026. Voor de basis van routing, zie routering van deep links: hoe je gebruikers naar het juiste scherm stuurt.
Het probleem
Elk platform heeft zijn eigen API om deep links te ontvangen:
- iOS:
application(_:continue:restorationHandler:)in AppDelegate of SceneDelegate - Android: Intent met
ACTION_VIEWafgeleverd aan de Activity - Web:
window.locationgeparsed bij het laden van de pagina - Capacitor/Ionic:
App.addListener('appUrlOpen', ...) - React Native:
Linking.addEventListener('url', ...) - Flutter:
uni_linksofapp_linkspackage
De URL komt binnen via verschillende API's, maar de vraag blijft altijd dezelfde: welk scherm moet de gebruiker zien bij dit pad en deze queryparameters?
Patroon 1: Gedeelde routetabel
Definieer routes in een platformonafhankelijk formaat. Het startpunt van elk platform parseert de URL en geeft die door aan de gedeelde tabel.
Routedefinitie
// routes.ts (gedeeld over alle platforms)
interface RouteMatch {
screen: string;
params: Record<string, string>;
}
interface RoutePattern {
pattern: RegExp;
screen: string;
paramNames: string[];
}
const routes: RoutePattern[] = [
{
pattern: /^\/products\/([^/]+)$/,
screen: 'ProductDetail',
paramNames: ['productId']
},
{
pattern: /^\/offers\/([^/]+)$/,
screen: 'OfferDetail',
paramNames: ['offerId']
},
{
pattern: /^\/referral\/([^/]+)$/,
screen: 'Referral',
paramNames: ['referrerId']
},
{
pattern: /^\/categories\/([^/]+)\/products$/,
screen: 'CategoryProducts',
paramNames: ['categoryId']
},
{
pattern: /^\/search$/,
screen: 'Search',
paramNames: []
}
];
export function matchRoute(urlString: string): RouteMatch | null {
const url = new URL(urlString);
const path = url.pathname;
for (const route of routes) {
const match = path.match(route.pattern);
if (match) {
const params: Record<string, string> = {};
route.paramNames.forEach((name, i) => {
params[name] = match[i + 1];
});
// Voeg queryparameters toe
url.searchParams.forEach((value, key) => {
params[key] = value;
});
return { screen: route.screen, params };
}
}
return null;
}
Platformspecifieke startpunten
iOS (Swift):
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard let url = userActivity.webPageUrl else { return false }
// Roep de gedeelde routinglogica aan (via de JavaScript-bridge, of implementeer die opnieuw in Swift)
let route = DeepLinkRouter.match(url: url)
if let route = route {
navigate(to: route.screen, params: route.params)
return true
}
return false
}
Android (Kotlin):
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent?.data?.let { uri ->
val route = DeepLinkRouter.match(uri.toString())
route?.let { navigateTo(it.screen, it.params) }
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
intent.data?.let { uri ->
val route = DeepLinkRouter.match(uri.toString())
route?.let { navigateTo(it.screen, it.params) }
}
}
Web:
// Bij het laden van de pagina of een routewijziging
const route = matchRoute(window.location.href);
if (route) {
renderScreen(route.screen, route.params);
}
Patroon 2: URL-naar-actie-koppeling
In plaats van URL's direct aan schermen te koppelen, koppel je ze aan acties. Zo ontkoppel je de deep link-laag van de navigatielaag.
// actions.ts
type DeepLinkAction =
| { type: 'VIEW_PRODUCT'; productId: string; source?: string }
| { type: 'VIEW_OFFER'; offerId: string }
| { type: 'APPLY_REFERRAL'; referrerId: string }
| { type: 'SEARCH'; query: string }
| { type: 'OPEN_HOME' };
export function urlToAction(urlString: string): DeepLinkAction {
const url = new URL(urlString);
const path = url.pathname;
const query = url.searchParams;
const productMatch = path.match(/^\/products\/([^/]+)$/);
if (productMatch) {
return {
type: 'VIEW_PRODUCT',
productId: productMatch[1],
source: query.get('ref') ?? undefined
};
}
const offerMatch = path.match(/^\/offers\/([^/]+)$/);
if (offerMatch) {
return { type: 'VIEW_OFFER', offerId: offerMatch[1] };
}
const referralMatch = path.match(/^\/referral\/([^/]+)$/);
if (referralMatch) {
return { type: 'APPLY_REFERRAL', referrerId: referralMatch[1] };
}
if (path === '/search') {
return { type: 'SEARCH', query: query.get('q') ?? '' };
}
return { type: 'OPEN_HOME' };
}
Elk platform implementeert zijn eigen actie-handler:
// iOS, Android en web implementeren elk deze interface
interface ActionHandler {
handleAction(action: DeepLinkAction): void;
}
// Voorbeeld: React Native-handler
class RNActionHandler implements ActionHandler {
handleAction(action: DeepLinkAction) {
switch (action.type) {
case 'VIEW_PRODUCT':
navigation.navigate('ProductDetail', {
productId: action.productId
});
break;
case 'APPLY_REFERRAL':
// Sla de verwijzing op en navigeer daarna
ReferralStore.save(action.referrerId);
navigation.navigate('Home');
break;
// ...
}
}
}
Dit patroon werkt goed als acties bijwerkingen hebben, zoals een verwijzingscode opslaan of een analytics-event versturen, voordat er genavigeerd wordt.
Patroon 3: Routes gestuurd door configuratie
Heb je apps met veel deep link-paden, definieer de routes dan in een configuratiebestand dat alle platforms inlezen:
{
"routes": [
{
"path": "/products/:productId",
"screen": "ProductDetail",
"requiresAuth": false
},
{
"path": "/account/settings",
"screen": "AccountSettings",
"requiresAuth": true
},
{
"path": "/offers/:offerId",
"screen": "OfferDetail",
"requiresAuth": false
},
{
"path": "/checkout/:cartId",
"screen": "Checkout",
"requiresAuth": true
}
]
}
Een gedeelde parser zet padpatronen om naar reguliere expressies:
function pathToRegex(path: string): { regex: RegExp; paramNames: string[] } {
const paramNames: string[] = [];
const regexStr = path.replace(/:([^/]+)/g, (_, name) => {
paramNames.push(name);
return '([^/]+)';
});
return {
regex: new RegExp(`^${regexStr}$`),
paramNames
};
}
Met deze aanpak blijven de routedefinities over alle platforms synchroon. Voeg je een nieuw deep link-pad toe, dan pas je het configuratiebestand één keer aan.
Platformverschillen afhandelen
Ook met gedeelde routinglogica verschillen sommige gedragingen per platform.
Authenticatiecontroles
Als een deep link naar een scherm met authenticatie leidt, hangt het gedrag af van de conventies van het platform:
function handleAuthenticatedRoute(
route: RouteMatch,
isLoggedIn: boolean,
platform: 'ios' | 'android' | 'web'
) {
if (isLoggedIn) {
navigate(route.screen, route.params);
return;
}
// Save the intended destination
saveDeepLinkDestination(route);
// Platform-specific login flow
if (platform === 'web') {
// Redirect to login page with return URL
window.location.href = `/login?returnTo=${encodeURIComponent(route.screen)}`;
} else {
// Show native login screen, then navigate after success
showLoginScreen();
}
}
Fallback-gedrag
Als een route niet overeenkomt, heeft elk platform een andere fallback:
| Platform | Fallback |
|---|---|
| iOS | Open het startscherm of toon een foutmelding |
| Android | Open het startscherm of laat het systeem het afhandelen (browser) |
| Web | Toon een 404-pagina of stuur door naar de startpagina |
function handleUnmatchedUrl(url: string, platform: string) {
if (platform === 'web') {
// Web kan een 404-pagina tonen
router.navigate('/not-found');
} else {
// Mobiele apps vallen netjes terug op de startpagina
router.navigate('/');
}
}
Routes synchroon houden
Het lastigste aan linkafhandeling over meerdere platforms is het synchroon houden van routes over:
- AASA-bestand (iOS-padpatronen)
- assetlinks.json (Android-verificatie)
- AndroidManifest.xml (prefixen van Intent filter-paden)
- App-router (routedefinities aan de clientkant)
- Backend (routeafhandeling aan de serverkant voor web)
Eén bron van waarheid
Genereer platformspecifieke configuratie op basis van één routedefinitie:
// generate-configs.ts
import routeConfig from './routes.json';
// Genereer AASA-componenten
function generateAASA(routes: Route[]) {
return {
applinks: {
details: [{
appIDs: ['TEAMID.com.yourcompany.yourapp'],
components: routes.map(r => ({
'/': r.path.replace(/:([^/]+)/g, '*')
}))
}]
}
};
}
// Genereer Android-intentfilterpaden
function generateIntentFilters(routes: Route[]) {
// Haal unieke padprefixen op
const prefixes = new Set(
routes.map(r => '/' + r.path.split('/')[1])
);
return Array.from(prefixes);
}
Zo voorkom je de veelvoorkomende fout dat een nieuwe route op het ene platform werkt en op het andere niet, omdat iemand vergeet de AASA- of Intent-filters bij te werken.
Cross-platformroutes testen
Test de gedeelde routinglogica met platformspecifieke test-URL's:
describe('matchRoute', () => {
const testCases = [
{
url: 'https://yourdomain.com/products/abc123',
expected: { screen: 'ProductDetail', params: { productId: 'abc123' } }
},
{
url: 'https://yourdomain.com/products/abc123?ref=email&campaign=summer',
expected: {
screen: 'ProductDetail',
params: { productId: 'abc123', ref: 'email', campaign: 'summer' }
}
},
{
url: 'https://yourdomain.com/unknown/path',
expected: null
}
];
testCases.forEach(({ url, expected }) => {
it(`komt overeen met ${url}`, () => {
expect(matchRoute(url)).toEqual(expected);
});
});
});
Tolinku voor cross-platformapps
Tolinku regelt het hosten van AASA en assetlinks.json, zodat je verificatiebestanden vanzelf up-to-date blijven. Het platform biedt ook deferred deep linking voor gebruikers die eerst de app moeten installeren.
Voor de uitdagingen bij hybride apps, zie deep linking in hybride apps: uitdagingen en oplossingen. 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.