M-Swift All articles
Swift Architecture

Your Deep Link Works Until It Doesn’t: Seven SwiftUI Navigation Patterns to Audit Now

M-Swift
Your Deep Link Works Until It Doesn’t: Seven SwiftUI Navigation Patterns to Audit Now

Photo: iOS developer auditing SwiftUI navigation stack deep link flow diagram on laptop, via www.nme.com

Deep links are a trust exercise. A user taps a password-reset email in Chicago, expects the app to open on the reset screen, and instead lands on the home tab with a spinner. The bug report says “deep link broken.” The real issue is usually navigation state: a root view swap, a hidden tab, a sheet that never dismissed.

I’ve audited enough SwiftUI apps to notice the same seven patterns. None of them look dangerous in code review. All of them can quietly break deep links, state restoration, and the back button. Here’s the checklist I use in 2026.

1. The onboarding gate that replaces the root

A common pattern is if !hasOnboarded { OnboardingView() } else { MainView() } at the app root. When a deep link arrives during onboarding, the app stores it, finishes onboarding, then swaps the root view. The swap resets the navigation stack, so the link opens the right tab but not the right screen.

Fix: keep one NavigationStack above the gate, or replay the route after the root swap with a router that owns the path. Treat onboarding as a route, not a separate universe.

2. The settings hierarchy with no path restoration

Settings screens often use NavigationLink(value:) and a local @State path. That works until the app is backgrounded, state restoration kicks in, or a push notification opens a nested settings screen. The path resets, and the user lands on Settings > root.

Fix: hoist the path into an observable router and encode routes as Codable. Restore only routes that still exist in the current build, and drop stale ones without crashing.

3. The tab that isn’t selected

A deep link points to a saved search inside the third tab. Your app opens the third tab’s NavigationStack, pushes the detail screen, but never switches selectedTab. The user sees the home tab and hears a back-button tap that goes nowhere.

Fix: resolve the deep link in two steps—select the tab, then push the route on that tab’s path. Keep an app-level URL router that knows which tab owns which route.

4. The sheet with its own stack

Sheets are where navigation gets sneaky. A link opens a profile edit sheet, the sheet builds its own NavigationStack, and the back button dismisses the entire sheet instead of popping one screen. Or the link arrives while the sheet is already open, and the app pushes a duplicate destination.

Fix: give the sheet a binding-driven isPresented value and a path owned by the presenter. Before pushing, check whether the sheet is already presented and whether the route is already on the path.

5. The auth flow that swaps the root

Sign-in flows love to replace the root view with a logged-in view. If a deep link arrives before authentication, the app may route to a detail screen, then wipe the stack when auth completes. The fix is not more DispatchQueue.main.asyncAfter calls.

Fix: model auth as a gate around route resolution. Resolve the link after auth, not before, and carry the pending route through the auth state. A single pendingRoute on the session router is enough.

6. The duplicate destination problem

Programmatic navigation with .navigationDestination(isPresented:) is convenient, but it can create two sources of truth: a boolean and a path. When a deep link pushes the same screen that a button already pushed, the user can tap back and see the same screen twice.

Fix: pick one navigation model per stack. Prefer value-based destinations and a path. If you must use isPresented, guard against duplicate presentation and reset the boolean when the path changes.

7. The stale universal link

Universal links often carry an ID that no longer exists. The app opens the detail screen, fetches nothing, and shows an empty state with no way home. That’s not a deep link failure; it’s a missing fallback.

Fix: validate the route before pushing. If the object is missing or the user lacks permission, route to a safe list screen with a clear message. Log the failure with the URL and the route resolution result.

A repeatable audit checklist

Run this on every screen that can be opened by URL, notification, or state restoration:

The goal isn’t a perfect navigation abstraction. It’s a stack that behaves the same whether the user taps a link, a button, or the back arrow. Audit these seven screens and your deep links will stop being a coin flip.

All Articles

Related Articles

Plain Structs, Clear Code: The Case Against Clever Swift Architecture

Plain Structs, Clear Code: The Case Against Clever Swift Architecture

I Migrated 50K Lines From XCTest to Swift Testing: The Wins, the Scars, and the Call I’d Make Today

I Migrated 50K Lines From XCTest to Swift Testing: The Wins, the Scars, and the Call I’d Make Today

Where Did the Sprint Go? A One-Week Build-Time Audit for Swift Teams

Where Did the Sprint Go? A One-Week Build-Time Audit for Swift Teams