How to tackle Routing in a SwitUI app (aka Deep Linking)

This year we got great new APIs to push forward how we build apps with SwiftUI, from @StateObject to GridItem or Lazy*Stack, a bunch of other new views. All great additions.

But there's something that I miss, I haven't seen documentation/examples on how should routing be managed in a SwiftUI app. How should deep link be tackled.

For example, how should we manage:
  • Opening an universal link

  • Opening a push notification with a deeplink

  • Continue User Activity: Navigating to a view opened with hand off.

  • State restoration: Navigate to the view the user was at, after the app was close

Do you have any examples on how should it be done? Or documentation on this topic? I'd love to see something in this regard.

Thank you.
It looks like you show a deeplink example in Fruta app (https://developer.apple.com/documentation/swiftui/fruta_building_a_feature-rich_app_with_swiftui, check out onContinueUserActivity in FrutaApp.swift).

Although it's good that I finally see an example from Apple, I think the community will benefit if it is covered in an article or documentation piece.
You can use LazyView (by Chris Eidhof): https://gist.github.com/chriseidhof/d2fcafb53843df343fe07f3c0dac41d5

Luca Bernardi, a SwiftUI engineer, said in a Twitter thread this is how SwiftUI works:

Exactly, SwiftUI expects view creation to be cheap: the system can recreate views often.
For example, allocating NSFormatter in the init is not a good: you’ll pay the cost of heap allocation (and initialization) every time the view hierarchy is updated.
(I can't link the referenced tweet here but the reference id of the tweet is 1144312093597769728.)

That said, I'd like to understand why it works like this for NavigationLink but not for views presented modally, and why not give us, the developers, the option built-in in SwiftUI, so we are left to choose the approach that fits best for us.
How to tackle Routing in a SwitUI app (aka Deep Linking)
 
 
Q