反应嵌套路由 - 未定义的匹配
React nested routes - undefined match
第一次使用嵌套路由,所以我按照这个例子和文章:
https://codesandbox.io/s/nested-routes-react-router-y5pt4?from-embed=&file=/src/index.js:2684-2693
https://learnwithparam.com/blog/how-to-handle-nested-routes-in-react-router/
但是,与示例相比,我正在获取的数据具有不同的结构,就像文章的集合。
https://content.guardianapis.com/search?api-key=test
我想做的是使用 pillarName 作为主导航栏。 sectionName 作为子导航栏,映射属于每个子类别的文章。
问题是,当我 console.log(":infoSectionName", match) WorldNews 组件时,我得到一个 undefined,所以我无法映射个人文章。
源代码:https://codesandbox.io/s/spring-silence-g6q66?file=/src/App.js:5802-5811
非常感谢您的建议。
尝试这样定义路线:
<Route path={`${match.path}/:infoSectionName`} component={WorldNews} />
第一次使用嵌套路由,所以我按照这个例子和文章:
https://codesandbox.io/s/nested-routes-react-router-y5pt4?from-embed=&file=/src/index.js:2684-2693 https://learnwithparam.com/blog/how-to-handle-nested-routes-in-react-router/
但是,与示例相比,我正在获取的数据具有不同的结构,就像文章的集合。
https://content.guardianapis.com/search?api-key=test
我想做的是使用 pillarName 作为主导航栏。 sectionName 作为子导航栏,映射属于每个子类别的文章。
问题是,当我 console.log(":infoSectionName", match) WorldNews 组件时,我得到一个 undefined,所以我无法映射个人文章。
源代码:https://codesandbox.io/s/spring-silence-g6q66?file=/src/App.js:5802-5811
非常感谢您的建议。
尝试这样定义路线:
<Route path={`${match.path}/:infoSectionName`} component={WorldNews} />