mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
docs: add programmatic navigation (#4074)
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
parent
75cbfbcb7e
commit
02f16bf23e
@ -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>
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user