navigateTo

Like useRouter or useRoute, navigateTo can also be used, both as a global import or from the @typed-router alias

<script setup lang='ts'>
await navigateTo({name: 'foo', params: { foo: 'bar' }});
</script>

Or with alias

<script setup lang='ts'>
import {navigateTo} from '@typed-router';

await navigateTo({name: 'foo', params: { foo: 'bar' }});
</script>

The resolved route with also be typed accordingly to the target route.

<script setup lang='ts'>
const route = await navigateTo({ name: 'foo', params: { one: 1, two: 2 } });
if (route instanceof Error) {
  // Do stuff
} else if (route) {
  console.log(route.params.bar); // Error! ❌
  console.log(route.params.foo); // Good! ✅
}
</script>