So we have built our first page: list of the posts. Now let's build the second page to add a new post. For this lesson, I will introduce the vue-router.

Installing and Enabling vue-router
First, we need to install the vue-router package.
npm install vue-router@latest
Then, we need to import vue-router.
resources/js/app.js:
import './bootstrap'; import { createApp } from 'vue'import { createRouter, createWebHistory } from 'vue-router' import PostsIndex from './components/Posts/Index.vue' createApp({}) .component('PostsIndex', PostsIndex) .mount('#app')
Then, we need to build a list of routes, initialize the router, and enable that router inside createApp().
Also, we don't need to define components in the createApp() anymore, as they are already defined in the routes.
resources/js/app.js:
import './bootstrap'; import { createApp } from 'vue'import { createRouter, createWebHistory } from 'vue-router'import PostsIndex from './components/Posts/Index.vue' const routes = [ { path: '/', component: PostsIndex },] const router = createRouter({ history: createWebHistory(), routes}) createApp({}) .component('PostsIndex', PostsIndex) .use(router) .mount('#app')
Vue Component for Second Page
Now, let's create a Vue component for the create post page...
Greate course, thanks
everything is good but when I try to use vue routes instead of web.php file not working
error Route [dashboard] not defined.
I would guess you left somewhere in the blade route dashboard
even though I checked this https://www.youtube.com/watch?v=L7dr3Zdq0vA but still not clear can you help :) ?
do I need to change all extension files inside this resources/views/.. into .vue ??
Nerijus, Can you explain in detail, plz ? I need help
Sorry I cannot debug for you without seeing the code
should I send you api.php , vue file and controller file ?
Hi Khalid,
according to https://v3.router.vuejs.org/guide/essentials/named-routes.html the links are replaced by <router-link :to=".... please note the ":" (which is missing above)
Isn't : (colon) used to when using routes with names and parameters?
i think in "Changing Layout: From Blade to Vue" point
we need to change resources/views/layouts/app.blade.php not in resources/views/dashboard.blade.php the correct one is "First, we will use the resources/views/layouts/app.blade.php file as a main HTML file where we set id="app" in the
tag, instead of the previous