Skip to content

Tree-based navigation with multiple .navigationDestination views #3090

Answered by mbrandonw
jessedoescode asked this question in Q&A
Discussion options

You must be logged in to vote

What if all of them would be .navigationDestination? I could handle them with separate .navigationDestination, but the expression becomes too complex for the compiler.

This is the way to do it, but you may need to employ some tricks to work around the compiler issues. You can move your navigation view modifiers to a helper like this:

extension View {
  func navigation(store: Binding<StoreOf<Feature>>) -> some View {
    self
      .navigationDestination(
        item: $store.scope(
          state: \.destination?.addItem,
          action: \.destination.addItem
        )
      ) { store in 
        AddItemView(store: store)
      }
      .navigationDestination(
        item: $store.scope(

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jessedoescode
Comment options

@mbrandonw
Comment options

Answer selected by jessedoescode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants