I have a simple navigation router:
@Observable class BaseRouter {
var path = NavigationPath()
var isEmpty: Bool {
return path.isEmpty
}
func navigateBack() {
path.removeLast()
}
func popToRoot() {
path.removeLast(path.count)
}
}
And a subclass:
class ProfileRouter: BaseRouter {
enum ProfileViewDestination {
case viewA
case viewB
}
enum ViewADestination: FormNavigationItem {
case viewC
}
func navigate(to destination: ProfileViewDestination) {
path.append(destination)
}
func navigate(to destination: ViewADestination) {
path.append(destination)
}
}
When using navigate(to:)
and navigateBack
functions all works fine, but when when using NavigationLink
and native navigation back button I see my path is not really updating, although the NavigationStack
is navigating currently.
So when going back from navigation button I can see my path still containing the appended item, and when I'll navigate to the screen again it will present it twice and so on.
One solution for this issue is to override the native back button but not only it will cause a loss of native functionality (back stack, swipe back) it adds a lot of redundant boilerplate code, so it is a bad solution IMO.
As for NavigationLink
I'm having the opposite issue, where it does not appending the proper item to the path and navigateBack
will go 2 levels back.
I'm sure I am missing something stupid here, or that's just not the way 'NavigationPath' meant to be used. either way I can't seems to find any good example for this one.
Ideas?!