If you have followed the chapters of this book from the beginning, you should already know how to install Vue Router from Chapter 4, Adding Views, Routes, and Transitions. However, here is a quick recap.
Follow these steps to download Vue Router directly:
- Click on the following link and download the source code:
https://unpkg.com/vue-router/dist/vue-router.js
- Include the router after Vue so that it can be installed automatically by itself:
<script src="/path/to/vue.js"></script>
<script src="/path/to/vue-router.js"></script>
Alternatively, you can install Vue Router via npm:
- Install the router to your project using npm:
$ npm i vue-router
- Register the router explicitly using the use method:
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
- Once you have the router in place, you can start creating middlewares using the navigation guards that come with Vue Router: