Dynamic routing
If there is a lot of data that follows the same format, such as a list of users or a list of messages, and it’s required to create a page for each of them, so we need to use a routing pattern. With a routing pattern, we can create a new route dynamically from the same component based on some additional information.
For example, we want to render the User
view component for every user but with different id
values. Vue Router provides us with the ability to use dynamic segments denoted by a colon (:
) to achieve dynamic routing.
Instead of using params
, which doesn’t persist its value when you refresh the page or appear in the URL, we define the required params
directly in the path as follows:
{ Â Â Â Â path: '/user/:id', Â Â Â Â name: 'user', Â Â Â Â component: () => import('../views/User.vue'), Â Â Â Â props: true, Â Â }
In the preceding...