title: How to switch to another view programmatically in SwiftUI (without a button press)
body: <p>I have a problem to switch to another view without pressing a button in my SwiftUI app.
  I can take many examples of what I want to do :
  1- Imagine a login form where we need to fill 2 textfields : username and password. When there's a perfect match we are automatically authenticated.
  2- Take my example now. I have this view :</p>
  
  <p><a href="https://i.stack.imgur.com/YmTI2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YmTI2.png" alt="enter image description here"></a></p>
  
  <p>What I want to do : when I select a row in the list (ex. Lyon-Perrache TGV) AND if the two textfields are not empty => I'm redirected to another view.</p>
  
  <p>There's many examples to know how to move to a view from another one, but always with a button click .. (with NavigationLink)
  I need to do this programatically exactly when the two textfields are filled AND when I select the destination textfield from the list.</p>
  
  <p>that's a part of my code :</p>
  
  <pre><code>import SwiftUI
  
  
  
  struct Search: View {
  
  
  
   @ObservedObject var webservice = Webservice()
  
   @State var Depart: String = ""
  
   @State var Destination: String = ""
  
   @State var listStation = [Station]()
  
   @State var predictedValues: Array&lt;String&gt; = []
  
   @State var isBeingEditedDeparture: Bool = false
  
   @State var isBeingEditedDestination: Bool = false
  
   @State var hey: Bool  = false
  
   @State var activate: Bool  = false
  
  
  
  init() {
  
        UITableView.appearance().showsVerticalScrollIndicator = false
  
        UITableView.appearance().backgroundColor = .clear
  
        UITableViewCell.appearance().backgroundColor = .clear
  
        //UITableView.appearance().separatorColor = .clear
  
    }
  
  
  
  var body: some View {
  
  
  
  
  
      VStack(alignment: .leading){
  
  
  
          PredictingTextField(listStation: self.$listStation , predictedValues: self.$predictedValues, 
          Depart: self.$Depart, Destination: self.$Destination, isBeingEditedDeparture: 
          self.$isBeingEditedDeparture, isBeingEditedDestination: self.$isBeingEditedDestination )
  
  
  
              .textFieldStyle(RoundedBorderTextFieldStyle())
  
  
  
          List() {
  
              ForEach(self.predictedValues, id: \.self){ value in
  
  
  
                  Text(value)
  
                      .onTapGesture {
  
                          if(self.isBeingEditedDeparture == true)
  
                          {
  
                              self.Depart = value
  
                          }
  
                          else{
  
                              self.Destination = value
                              self.activate = true
  
                          }
  
                  }
  
              }
  
          }.padding(.top, 10)
  
  
  
      }
  
  }
  </code></pre>
  
  <p>I have declared a variable named "activate" to be the trigger point of moving to the new View. 
  It's equal to true when we select a row in the list for "destination" textfield.</p>
  
  <p>How can I do to go further ?</p>
  
  <p>Thank you in advance !</p>
  
  <p><a href="https://i.stack.imgur.com/NYn0b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NYn0b.png" alt="error"></a></p>