[Vuejs]-Is this correct params passing in vue router 4?

0๐Ÿ‘

I think you confused path params with query params.

For example in /users/123?tab=info 123 (user id) is a path parameter, while tab=info is a query parameter.

If you want a path parameter: /clients/persons

In Vue Router, you can describe a path parameter in the route by prefixing it with a colon:

{
  path: "/clients/:tab",
  name: "Clients",
}

Then you would be able to use it like that:

// while navigating
router.push({ name: 'Clients', params: { tab: 'persons' })

// on the page
route.params.tab

If you want a query parameter: /clients?tab=persons

You can simply use query attribute of a route:

// while navigating
router.push({ name: 'Clients', query: { tab: 'persons' })

// on the page
route.query.tab

Leave a comment