VueJS does not have a built-in router feauture. We need to follow some additional steps to install it.
Direct Download from CDN
The latest version of vue-router is available at https://unpkg.com/vue-router/dist/vue-router.js
The router-link is what we use to generate the links, with “to” we set the path. the router-view, as the comment in the code, says is the place where the routed component is going to render.
First, we set a couple of vuejs components (route1 and route2) so we have something to bind the routes to.
Then we create the routes object with three paths configurations:
- The first path (“route1”), renders the route1 component.
- The second path (“route2”), renders the route2 component.
The VueRouter constructor takes the routes as the param. The router object is assigned to the main Vue instance using the following piece of code.