push route with params vue code example

Example 1: vue router.push with params

// literal string path
router.push('/users/eduardo')

// object with path
router.push({ path: '/users/eduardo' })

// named route with params to let the router build the url
router.push({ name: 'user', params: { username: 'eduardo' } })

// with query, resulting in /register?plan=private
router.push({ path: '/register', query: { plan: 'private' } })

// with hash, resulting in /about#team
router.push({ path: '/about', hash: '#team' })

Example 2: vue router name

<router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>

Example 3: vue router name

router.push({ name: 'user', params: { userId: 123 }})