0

My first day with Vue. I initialized my app. I want to add a Login component, when I set routes in main.js, no page works.

import Vue from 'vue'
import App from './App.vue'

import VueRouter from 'vue-router'

import Login from './components/Login.vue'

const routes = [
  { path: '/', component: App },
  { path: '/login', component: Login }
]

const router = new VueRouter({
  mode: 'history',
  routes 
})

new Vue({
  router
}).$mount("#app")

Only works when I add render option to Vue object and renders the App component.

new Vue({
  router,
  render: h => h(App) // or Login
}).$mount("#app")

How will I ensure rendering route components?

1 Answer 1

2

You should add router-view component inside your App component like :

<template>
   <div>
     <router-view></router-view>
  </div>
</template>
Sign up to request clarification or add additional context in comments.

2 Comments

Great thank you. Now, I can't see content of Login, what I see is only template of App.vue.
you could visit the link youbaseUrl/login something like http://127.0.0.1:8080/login please check this full example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.