After initializing a new Vue project using @vue/cli $> vue create my-project
, I opted for Typescript and router options, then updated to vue3 beta using $>vue add vue-next
.
Unfortunately, when running $>npm run serve
, I encountered the following error:
ERROR in /home/auser/dev/my-project/src/router/index.ts(1,10):
1:10 Module '"../../node_modules/vue-router/dist/vue-router"' has no exported member 'RouteConfig'.
> 1 | import { RouteConfig, createRouter, createWebHistory } from 'vue-router';
| ^
2 | import Home from '../views/Home.vue'
Although the file is relatively short, the issue seems to arise due to the use of RouteConfig:
//index.ts
import { RouteConfig, createRouter, createWebHistory } from 'vue-router';
import Home from '../views/Home.vue'
const routes: Array<RouteConfig> = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router
Q: Can you advise on the correct type of RouteConfig required for createRouter
?