In my Vue-Router 4 setup, I am trying to combine multiple file.ts files with the main vue-router (index.ts) using TypeScript. However, it throws an error that says "TS2769: No overload matches this call. Overload 1 of 2, '(...items: ConcatArray[]): never[]', gave the following error. Argument of type 'RouteRecordRaw[]' is not assignable to parameter of type 'ConcatArray'. The types returned by 'slice(...)' are incompatible between these types. Type 'RouteRecordRaw[]' is not assignable to type 'never[]'...."
Below are the contents of my files.
DashboardRouter.ts
import { RouteRecordRaw } from "vue-router";
const DashboardRouter: Array<RouteRecordRaw> = [
{
path: "/",
redirect: "/dashboard",
component: () => import("@/layout/Layout.vue"),
children: [
{
path: "/dashboard",
name: "dashboard",
component: () => import("@/views/Dashboard.vue"),
},
]
},
];
export default DashboardRouter;
GuestRouter.ts
import { RouteRecordRaw } from "vue-router";
const GuestRouter: Array<RouteRecordRaw> = [
{
path: "/login",
name: "login",
component: () => import("@/views/auth/Login.vue")
},
{
path: "/password-reset",
name: "password-reset",
component: () => import("@/views/auth/PasswordReset.vue")
},
{
// the 404 route, when none of the above matches
path: "/404",
name: "error-404",
component: () => import("@/views/error/Error404.vue")
},
{
path: "/:pathMatch(.*)*",
redirect: "/404"
}
];
export default GuestRouter;
Index.ts(Main Router)
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import store from "@/store";
import { Mutations, Actions } from "@/store/enums/StoreEnums";
import DashboardRoute from "./DashboardRouter";
import GuestRoute from "./GuestRouter";
const routes: Array<RouteRecordRaw> = [].concat(GuestRoute, DashboardRoute);
const router = createRouter({
history: createWebHistory(),
routes
});
router.beforeEach(() => {
// reset config to initial state
store.commit(Mutations.RESET_LAYOUT_CONFIG);
// Scroll page to top on every route change
setTimeout(() => {
window.scrollTo(0, 0);
}, 100);
});
export default router;