问题描述:NUXT3项目切换页面跳转控制台报错,页面不显示:
Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
翻译过来的意思是:在“Node”上执行“insertBefore”失败:要插入新节点的节点不是此节点的子节点。
在官网查了一下发现了问题所在: 官网
Pages must have a single root element to allow route transitions between pages. HTML comments are considered elements as well.
This means that when the route is server-rendered, or statically generated, you will be able to see its contents correctly, but when you navigate towards that route during client-side navigation the transition between routes will fail and you'll see that the route will not be rendered.
翻译:页面必须有一个根元素,以允许页面之间的路由转换。HTML注释也被视为元素。
这意味着,当路由由服务器渲染或静态生成时,您将能够正确查看其内容,但当您在客户端导航期间导航到该路由时,路由之间的转换将失败,您将看到路由不会被渲染。
解决办法:路由对应的页面确保有一个根元素!!!
虽然Vue3 支持多个根元素,但在 Nuxt3 里面,如果进入多根元素页面,再跳转去其他页面,会导致页面空白,控制台会报上面的错误。
请避坑