Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

javascript - React Native How To Convert Route to Navigation State

I am trying to implement react navigation v5's deep linking system to my react native app. So far its working but I am started get confused. So my aim is make initial screen to get params while navigating to specified screen. I can explain it better with code:

const config = {
screens: {
    HomeStack: {
        screens: {
            Home: {
                screens: {
                    SearchStack: {
                        initialRouteName: 'Search',
                        screens: {
                            PostDetailStack: {
                                initialRouteName: 'PostDetail',
                                screens: {
                                    PostDetail: 'post-detail/:postId',
                                    CommentDetail: 'post-detail/:postId/:comment/:commentId'
                                } 
                            }
                        }
                    }
                }
            } 
        }
    },
    AuthStack: {
        screens: {
            ChangePassword: 'reset/:uid/:token'
        }
    }
}
}

So while navigating to CommentDetail screen I also want to pass params to PostDetail screen. In react navigation docs it says I need to use getStateFromPath(path, config) to copy params but I don't know how to use that. I tried to convert this route to state but I got confused and I also don't get when we use index in navigation state and when we don't. So how can I convert this to proper navigation state that initial screen also gets the params?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...