Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Configure Named Routes in Vue.js and Nuxt.js

    John LindquistJohn 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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.