skip to content

Stack-Based Routing

NavigationStack pushes from a bound array or NavigationPath, so code can push, pop and restore a stack. Interviewers ask how a router owns that path and serves deep links.

on this pageshow

explore

questions

5

With SwiftUI's NavigationStack, when do you bind a typed array versus a NavigationPath, and how do you push, pop and pop to root?

level: middleimportance: must knowfreq 68%

basics

~20 s

Bind a typed array when every pushed value shares one route type, so code can read it; bind a NavigationPath when one stack mixes types. Push with append, pop with removeLast, and pop to root by emptying the path.

open as a page

How do you restore a SwiftUI NavigationStack's path after relaunch, and why can NavigationPath's codable property return nil?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Make every route value Codable, encode the path when the scene goes to the background, and decode it at launch. NavigationPath's codable returns nil when any element in the path isn't Codable, because the path itself only requires Hashable.

open as a page

In a modular SwiftUI app, how do feature modules register their screens on a shared NavigationStack, and does that push you toward a NavigationPath or a typed array of one app-wide route enum?

level: principalimportance: should knowfreq 30%

basics

~20 s

Each feature exports a Hashable route type and a modifier that calls navigationDestination(for:) for it; the app target applies those modifiers at each stack's root. A NavigationPath then holds every feature's routes without a shared enum but is opaque; one app-wide enum keeps the path typed but must know every feature.

open as a page