使用react中的router v6版本踩坑记录。
按照A is only ever to be used as the child of element, never rendereddirectly.Please wrap your in a 这篇文章设置完最新版本的路由后,出现了这样的报错,useRoutes() may be used only in the context of a <Router> component.,经过查询之后,从这里找到了解决答案,useRoutes() may be used only in the context of a component.
解释如下:

在这里插入图片描述
最后的解决方法,最路由标签最外层再包裹一层BrowserRouter标签,
这是我的index.js文件,在这里插入图片描述
这是我的App.js文件,在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐