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';

Vue.use(VueRouter);

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

const router = new VueRouter({
  routes,
});

new Vue({
  render: h => h(App),
  router,
}).$mount('#app');

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

Post your Answer