useRouter

You can use useRouter the same way as before.

If you have a [foo].vue page file, you can navigate to it like this:

<script setup lang='ts'>
const router = useRouter();

router.push({name: 'foo', params: { foo: 'bar' }})
</script>

If you have a [foo]-[[bar]].vue page file, the bar param will be correctly infered as optional in the params option

<script setup lang='ts'>

const router = useRouter();

router.push({name: 'foo-bar', params: {foo: 1 }}) // params: {foo: string | number, bar?: string | number}
</script>

If you have a "catch all" page [...slug].vue, the typings will help you providing params

<script setup lang='ts'>

const router = useRouter();

router.push({name: 'slug', params: { slug: ['bar', 'baz'] }})
</script>