1
以下是我想要配置嵌套路線反應路由器:如何使用react-router從URL解耦用戶界面?
<Route path="/" component={App}>
<Route path="student/:studentId" onEnter={checkAuth} component={Student}>
<Route path="edit" onEnter={checkAuth} component={StudentForm} />
</Route>
</Route>
的student/:studentId
網址應顯示的特定studentId
所有細節。
嵌套的student/:studentId/edit
應顯示一個窗體來編輯以前顯示的值。
我想避免的是必須將StudentForm
組件嵌套在Student
組件內,並直接在App
的內部顯示錶格。
我一直在閱讀react-router
回購的所有文檔,尤其是這一個:Decoupling the UI from the URL,但它解釋完全相反(如何讓組件嵌套在另一個組件中,但可通過不同的url訪問)。
我可以檢查url是否爲edit
並呈現表單而不是學生列表,但我希望避免條件呈現。
有沒有人知道使用react-router
實現這一目標的方法?