docs: add programmatic navigation (#4074)

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
Dan Pastori 2022-04-07 04:46:47 -07:00 committed by GitHub
parent 75cbfbcb7e
commit 02f16bf23e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -299,3 +299,27 @@ export default defineNuxtConfig({
}
})
```
## Programmatic Navigation
Nuxt 3 allows programmatic navigation through the `navigateTo()` utility method. Using this utility method, you will be able to programmatically navigate the user in your app. This is great for taking input from the user and navigating them dynamically throughout your application. In this example, we have a simple method called `navigation()` that gets called when the user submits a search form.
**Note:** Ensure to always `await` on `navigateTo` or chain it's result by returning from functions.
```vue
<script setup>
const router = useRouter();
const name = ref('');
const type = ref(1);
function navigate(){
return navigateTo({
path: '/search',
query: {
name: name.value,
type: type.value
}
})
}
</script>
```