Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 986 of the free egghead.io lessons, plus get Vue.js content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Configure Named Routes in Vue.js and Nuxt.js

1:02 Vue.js lesson by

As you create more and more routes, the paths become difficult to manage and concatenate the parts together as just a giant string. Using named routes allows you to reference the route by a simple string then pass in the params as an object. This lesson covers configuring named routes in Nuxt.js in the nuxt.config.js and the passing the named route to a router-link.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

As you create more and more routes, the paths become difficult to manage and concatenate the parts together as just a giant string. Using named routes allows you to reference the route by a simple string then pass in the params as an object. This lesson covers configuring named routes in Nuxt.js in the nuxt.config.js and the passing the named route to a router-link.

With routes, it's often way more convenient to have a named route, instead of worrying about the path, and then mapping to the path in a router link like this. The way you set up a name for your route is pretty self explanatory. You give it a property of name. Going to name this "user". Now, I have a named route.

In my index, instead of putting together a URL to navigate to, I can delete all of this, and instead evaluate an object that has a name. I'm telling it to grab my "user" route based on that name. It has params, and this is another object with an ID of person.id.

Now, this has become much more flexible if you need to move things around inside of your params, or if you're changing around URLs and you just want to keep the names intact inside of your router links, because now, everything just works the exact same, so refresh.

Click on Palpatine, and we still have Palpatine, and all the other users work, as well.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?