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

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet
Published 5 years ago
Updated 3 years ago

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.

[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.