Vue Router 复制名称未定义的路由
我有 Vite 应用程序和使用 https://github.com/hannoeru/vite- 自动路由的路由插件页面。当我在 router/index.ts 文件上使用 console.log() 时,它会显示正确的路由。但是,当我尝试使用 router.getRoutes() 来 console.log()
组件上的路由时,它显示了一些名称重复的路由:undefined
。
router/index.ts
console.log("Routes", newRoutes)
const router = createRouter({
history: createWebHistory(BASE_URL),
routes: newRoutes,
})
布局/default.vue
const router = useRouter();
console.log("Router naon", router.getRoutes());
我尝试查看我的 Nuxtjs 应用程序,它似乎没有重复这样的内容。这成为了问题,因为当我尝试使用 name
推送路由器时,它没有转到正确的页面。
I have Vite apps and routing using automatic routing with https://github.com/hannoeru/vite-plugin-pages. When I console.log()
on the router/index.ts
file, it shows the right routes. But when I tried to console.log()
the routes on component with router.getRoutes()
it shows some duplicated route with name: undefined
.
router/index.ts
console.log("Routes", newRoutes)
const router = createRouter({
history: createWebHistory(BASE_URL),
routes: newRoutes,
})
layouts/default.vue
const router = useRouter();
console.log("Router naon", router.getRoutes());
I have tried looking on my Nuxtjs apps and it seems like it doesn't duplicated anything like this. This became problem because when I tried to push router with name
, it doesn't go to the right page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了一些挖掘,结果发现这是由 https://github 引起的。 com/JohnCampionJr/vite-plugin-vue-layouts - 该插件基本上采用您的路线并将布局设置为组件。然后,它使用原始路由创建一个新的子路由。他的 github 上有一些与此相关的问题 (issues/55, 问题/92)。我无法确定这是否是预期的行为,因为我认为原始路线确实应该被删除,并且具有新布局和子路线的路线应该取代它。
I did a bit some digging and turns out this is being caused by https://github.com/JohnCampionJr/vite-plugin-vue-layouts - the plugin basically takes your routes and sets the layout as the component. It then creates a new child route with the original route. There are a few issues about this on his github (issues/55, issue/92). I can't work out if it's the intended behaviour or not as I think the original route should really be removed and the route with the new layout and child route should replace it.