frzi / swiftui-router

Path-based routing in SwiftUI
MIT License
900 stars 43 forks source link

Support nested route #24

Closed jeemyeong closed 3 years ago

jeemyeong commented 3 years ago

Hi, I am using this library.

I cannot find out how to use nested route, so is it able to use nested route? If available, could you give me some examples?

frzi commented 3 years ago

What exactly do you mean with nested route? You can place a Route anywhere in your View hierarchy (as long as it's inside a Router). Even Routes inside Routes, using relative paths:

@main
struct MyApp: App { 
    var body: some Scene {
        WindowGroup {
            Router(initialPath: "/one/two/three") {
                Route(path: "one/*") {
                    Text("One")

                    Route(path: "two/*") {
                        Text("Two")

                        Route(path: "three") {
                            Text("Three")
                        }
                    }
                }
            }
        }
    }
}

Just make sure to use * at the end of a path to also match deeper paths. (E.g.: /one would not match /one/two, but /one/* does match)

jeemyeong commented 3 years ago

Thank you, I exactly got what I want. 👍