vue: Configure Named Routes in Vue.js and Nuxt.js
1:02 Vue.js lesson byJohn Lindquist
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 .Share this lesson: Facebook Twitter Google+
Get the Code Now
click to level upComment Guidelines
Member comments are a way for PRO Members to communicate, interact, and ask questions about a lesson.Commenting Guidelines
Here are some basic guidelines for commenting on egghead.io.Be on-topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contactclick here.Avoid meta-discussion
Is your comment resembles:This was great! This was horrible! I didn't like this because it didn't match my skill level. +1
It will likely be deleted as "meta".Code problem?
Should be accompanied by code! JSFiddle, Plunker, CodePen, etc all provide a way to share code and discuss it in context.Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!
egghead.io comment guidelines
egghead.io about 12 hours ago
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.
本文标题：vue: Configure Named Routes in Vue.js and Nuxt.js