Vue Router Documentation: https://router.vuejs.org/installation.html
1) In terminal run the command:
npm install vue-router
2) As we will have many routes, so we will make a new file for that inside resources -> js create
router.js file.
3) Open router.js file and import Vue & Router:
Now, we will use the route. So, in router.js file:
Here, we have given a path url name (you can give anything as url name). and the component is blank.
we will first make a folder called pages inside resources -> js -> components.
and, create a file inside pages folder called myFirstVuePage.vue .
4) Inside myFirstVuePage.vue file write:
5) Now, again go back to router.js file, we will import this component.
Write import in router.js file like the following example and use in component:
6) and we need to import routes in app.js file:
7) Inside mainapp.vue write:
8) In terminal run: npm run watch
9) Now hit the /my-new-vue-route and you will see the the component is loaded successfully.
Comments
Post a Comment