From the course: Learning Nuxt.js

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Dynamic routes

Dynamic routes

- Another way we can handle routing is with dynamic routes. You can use this method when you're unsure of the name of the route you want to create like when you're dealing with dynamic data or you try to fetch data from an API. Let's see how this works. To create a dynamic route you need to prefix the view file or the name of the directory with an underscore followed by the name you would like to give it. The dynamic file tree can look something like this code block. When we create a dynamic page named _slug.vue inside the pages directory, it will automatically generate the following route configuration we see on screen. From this example we can show this in action by displaying the route parameters or the name of the slug directly inside the page using NOx routes objects. Let's head over to the code editor and see what that looks like. Inside the pages directory I'll create a new file and call this new file _slug.vue…

Contents