2 Replies
Hi @o.m. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Certainly! I'd be happy to provide you with examples of dynamic routes in Nuxt. Dynamic routes are a powerful feature that allows you to create flexible and reusable page components.
Here's a sample of how to use dynamic routes in Nuxt:
1. Create a file with square brackets in its name to define a dynamic segment:
In this example,
[id]
is the dynamic part of the route.
2. In your [id].vue
file, you can access the dynamic parameter using the useRoute()
composable:
This setup will match routes like /users/1
, /users/2
, etc., and userId
will contain the value of the dynamic segment.
For more complex scenarios, you can also use catch-all routes. Here's an example:
This will match any route under /articles/
, such as /articles/2023/best-practices
.
You can access the parameters like this:
These examples are based on the information from Nuxt Documentation on Routing (https://nuxt.com/docs/getting-started/routing).
Remember that Nuxt automatically generates the router configuration based on your file structure in the pages/
directory, making it easy to create dynamic routes without additional configuration.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@674984670156423171> Kapa.ai is still learning and improving, please let me know how I did by reacting below.