router.push({ path: '/user', params: { username } }) // -> /user
```
-When specifying `params`, make sure to either provide a `string` or `number` (or an array of these for [repeatable params](./route-matching-syntax.md#repeatable-params)). **Any other type (like `undefined`, `false`, etc) will be automatically stringified**. For [optional params](./route-matching-syntax.md#optional-parameters), you can provide an empty string (`""`) as the value to skip it.
+When specifying `params`, make sure to either provide a `string` or `number` (or an array of these for [repeatable params](./route-matching-syntax.md#repeatable-params)). **Any other type (like objects, booleans, etc) will be automatically stringified**. For [optional params](./route-matching-syntax.md#optional-parameters), you can provide an empty string (`""`) or `null` as the value to remove it.
Since the prop `to` accepts the same kind of object as `router.push`, the exact same rules apply to both of them.
| --------------------------------- | --------------------- |
| `<router-link :to="..." replace>` | `router.replace(...)` |
-It's also possible to directly add a property `replace: true` to the `routeLocation` that is passed to `router.push`:
+It's also possible to directly add a property `replace: true` to the `to` argument that is passed to `router.push`:
```js
router.push({ path: '/home', replace: true })
await router.push({ name: 'optional', params: {} })
})
- it('removes null/undefined params when current location has it', async () => {
+ it('removes null/undefined optional params when current location has it', async () => {
const { router } = await newRouter()
await router.push({ name: 'optional', params: { p: 'a' } })
expect(router.currentRoute.value.params).toEqual({})
})
- it('keeps empty strings', async () => {
+ it('keeps empty strings in optional params', async () => {
const { router } = await newRouter()
const route1 = router.resolve({ name: 'optional', params: { p: '' } })
expect(route1.params).toEqual({ p: '' })