How to handle routing in a Vue.js application using Vue Router?

Vue Router is the official routing library for Vue.js. It allows you to define routes and navigate between different views in a Vue.js application.

// main.js
import Vue from 'vue';
import App from './App.vue';
import VueRouter from 'vue-router';
import Home from './components/Home.vue';
import About from './components/About.vue';


const routes = [
  { path: '/', component: Home },
  { path: '/about', component: About },

const router = new VueRouter({

new Vue({
  render: h => h(App),

Then, you can use <router-link> for navigation in your templates.

Post your Answer