如何从 ToolbarItem 推送视图?

How can I push a view from a ToolbarItem?

ToolbarItem(placement: .bottomBar) {
    NavigationLink(
        destination: NoteView(note: Note())
    ) {
        Image(systemName: "square.and.pencil")
    }
}

此代码未按预期运行:当我点击图像时未执行任何操作。

知道原因或方法吗?

一个可能的解决方法是将 NavigationLink 移到 toolbar 之外并使用 isActive 参数激活:

struct ContentView: View {
    @State var linkActive = false

    var body: some View {
        NavigationView {
            Text("Test")
                .background(
                    NavigationLink(destination: Text("Destination"), isActive: $linkActive) {}
                )
                .toolbar {
                    ToolbarItem(placement: .bottomBar) {
                        Button(action: {
                            linkActive = true
                        }) {
                            Image(systemName: "square.and.pencil")
                        }
                    }
                }
        }
    }
}