Skip to main content

Vue Route Names and Separate File

Premium
3 min read

In this lesson, we will perform some route cleanup in Vue. We will introduce route naming and move the routes into a separate file.


Named Routes

So let's add a name to the routes.

resources/js/app.js:

import './bootstrap';
 
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import App from './layouts/App.vue'
import PostsIndex from './components/Posts/Index.vue'
import PostsCreate from './components/Posts/Create.vue'
 
const routes = [
{
path: '/',
name: 'posts.index',
component: PostsIndex
},
{
path: '/posts/create',
name: 'posts.create',
component: PostsCreate
},
]
 
const router = createRouter({
history: createWebHistory(),
routes
})
 
createApp(App)
.use(router)
.mount('#app')

So how to use them by name now? In the main App layout...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 41 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

AA
Ayenan Alphonse SOSSOU ✓ Link copied!

Thanks for a so resourcefull course, really well explained

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.