Encountering the same bug of code inference error due to a loop reference in my code.
I defined a route array constant in route.ts
, like this:
import { RouteRecordRaw, createRouter, createWebHistory } from "vue-router";
import Layout from "../layout/index";
export const NaviHeaderRoutes: RouteRecordRaw[] = [
{
path: "/foo",
// Remaining code omitted for brevity...
];
const routes: RouteRecordRaw[] = [
...NaviHeaderRoutes
];
const router = createRouter({
history: createWebHistory(),
routes
});
export default router;
Then I used NaviHeaderRoutes
in the child component of Layout.vue
// layout.vue
// Remaining code omitted for brevity...
<sciprt lang="ts" setup>
//Remaining code omitted for brevity...
</script>
// naviheader
// Remaining code omitted for brevity...
<script lang="ts" setup>
import {NaviHeaderRoutes} from '@/router'
//Remaining code omitted for brevity...
</script>
The fix is simple, just ensure to set the route
's component later in your code.
export const NaviHeaderRoutes: RouteRecordRaw[] = [
{
path: "/foo",
name: "FOO",
redirect: "/foo/index",
// component: Layout,
// ....
]
const routes: RouteRecordRaw[] = [
...NaviHeaderRoutes.map((x) => {
x.component = Layout;
return x;
})
];