Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid route component in new VueJs Project

I’m working on a Vue.js project and encountered an error that says "Error: Invalid route component." I’m having trouble figuring out the root cause of this issue. Can someone please help me diagnose and resolve it?

import { createRouter, createWebHistory } from "vue-router";
import Home from '../views/Home.vue' 
const routes = [
  {
    path: "/",
    name: "home",
    component: "Home",
  },
];
const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;

<template> 
  <router-view />
</template>

<script setup> 

</script>

<style scoped> 
</style>

import { createApp } from "vue";
import router from "./router";
import "./style.css";
import App from "./App.vue";

createApp(App)
    .use(router)
    .mount("#app");

<template>
    Home
</template>

<script setup>
</script>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Have a look at the component value, it’s a string, it should be a reference to your Home import:

import Home from '../views/Home.vue' 
const routes = [
  {
    path: "/",
    name: "home",
    component: Home, // <---- use Home, not "Home"
  },
];

Give it a go.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading