0

I am currently refactoring my navigation system from NavigationView to the new NavigationStack and I have a view in which if the user presses a button and has a certain device (i.e iPhone SE) then it redirects him to a specific view, and if he doesn't have a certain device the navigation will redirect him to another view.

Here is how I tried to do it

I have the following NavigationLink inside the body:

NavigationLink(value: SignUpDate(deviceName: UIDevice.modelName)) {
    Button {
        print("log in btn")
    } label: {
        Text("Log In")
            .frame(minWidth: 0, maxWidth: 280)
            .font(Font.headline.weight(.bold))
    }
    .buttonType1()
}

And my NavigationStack has this modifier:

    .navigationDestination(for: SignUpDate.self) { destination in
        print(destination.deviceName)
        if isDeviceRestricted == true {
            RestrictedDeviceView()
        } else {
            SignUpDateView()
        }
    }

SignUpDate is as follows:

struct SignUpDate: Hashable {
    let deviceName: String
}

I don't know what I'm doing wrong but the button actually does nothing, it just acts as if there was no link in the first place.

HangarRash
  • 7,314
  • 5
  • 5
  • 32
  • 1
    `NavigationLink` is already a button, no need for another `Button` inside. Remove it. If you want to perform some action as you press the `NavigationLink`, see: https://stackoverflow.com/questions/57666620/is-it-possible-for-a-navigationlink-to-perform-an-action-in-addition-to-navigati – workingdog support Ukraine Aug 17 '23 at 00:02

0 Answers0