前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >解决react-router-dom V6路由嵌套时,子路由无法显示的问题

解决react-router-dom V6路由嵌套时,子路由无法显示的问题

作者头像
江咏之
发布2022-09-23 08:40:31
2.4K0
发布2022-09-23 08:40:31
举报
文章被收录于专栏:技术社区

警告提示:You rendered descendant <Routes> (or called useRoutes()) at "/home" (under <Route path="/home">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.

在这里插入图片描述
在这里插入图片描述

App.tsx

router v5的写法

代码语言:javascript
复制
  <Route path="/home" element={<Commonview />}></Route>
在这里插入图片描述
在这里插入图片描述

Commonview组件

在这里插入图片描述
在这里插入图片描述

子路由页面无法显示,并警告:You rendered descendant <Routes> (or called useRoutes()) at "/home" (under <Route path="/home">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.

在这里插入图片描述
在这里插入图片描述

经查阅文档可知: v6 中,所有路由路径始终是完全匹配,不再像v4/5中那样匹配路径前缀。父/根路径需要指定 * 通配符,以便它们现在可以进行"前缀"匹配,所以解决办法是在App.tsx加上通配符*

代码语言:javascript
复制
<Route path="/*" element={<Commonview />}></Route>
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

问题完美解决!

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-08-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档