Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Add Custom Routes for Hidden Pages with Vue.js and Nuxt.js

    John LindquistJohn Lindquist

    Sometimes the pages/ directory structure doesn't meet your needs, so you'll need to customize your routes manually. Using the nuxt config and "hidden pages" you can map routes to view components without getting in the way of the default pages routing.

    vueVue.js
    nuxtNuxt.js
    Code

    Code

    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
    Transcript

    Transcript

    00:00 A hidden page is a page that you create that starts with an underscore, we'll call this user view that had a template in there with the div of H1 saying, "Find me." If I try and navigate to this _user, we'll get our 404, or just user I'll get that same 404.

    00:21 You can use these hidden pages to route to in your next config. In my config I'll configure the router which is an object which has routes inside of it. This is an array. This array has objects with that path. The path can just be /user, and then a component to map to.

    00:44 Our component will be pages/_user. Now I'm going to hit Save, and I refresh on my user URL. We can find and display the user view hidden page at this user URL, because we configured our router to have a route with the path of user and a component of _user.

    Discuss

    Discuss