Skip to content

Navigate navigates into void sometimes #39

@koraykoska

Description

@koraykoska

Very randomly, without any consistency, I see that Navigate tries to navigate to a route, then chooses to make a wrong turn to the default route in the last step (inside a SwitchRoutes) and then repeats itself a few times until SwiftUI decides to stop it and renders an empty screen.

I had this issue multiple times and most of the time it was an endless loop caused by my code. This time, however, I even checked the info parameter and can see that it took a wrong turn, even though the route is set correctly.

I can't really provide a sample project as it is anyways very random and happens just sometimes. I was just hoping that someone experienced this as well and knows where I can start debugging.

Just as a presentation of what I mean, see the below:

struct MainRouter: RouterView {
    var content: some View {
        Router(initialPath: "/sign-in") {
            SwitchRoutes {
                Route("/sign-up/*") {
                    SignUpRouter()
                }

                Route("/sign-in/*") {
                    SignInRouter()
                }

                Route("/home/*") {
                    HomeRouter()
                }

                Route {
                    Navigate(to: "/sign-in")
                }
            }
        }
    }
}

// --- Removing all the other Routers for brevity. This only happens on HomeRouter for some reason.

struct HomeRouter: RouterView {
    var content: some View {
        SwitchRoutes {
            Route("root") {
              SomeHomeView()
            }

            Route("profile") {
              SomeProfileView()
            }

            Route { info in
                // The case is described below. info tells me that the route is /home/profile but for some reason it lands here in the fallback.
                Navigate(to: "/home/root")
            }
        }
    }
}

So the issue arises if I navigate to "/home/profile" (or any other subview of home). What happens instead (again, just sometimes), is that the Navigator jumps to the fallback Route {}. The weird thing is that the info variable has the right path saved. For some reason, it just doesn't match the right one when selecting the path to navigate to.

I know that this can be caused by literally everything and probably depends on my app state. Still good to have this open and see if anyone else is experiencing this.

In general, I would like to understand how this situation CAN happen with SwiftUIRouter. Once I do, it will be much easier to debug and solve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions