This repository was archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 984
docs(api): add navigateTo docs
#5701
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be99c17
docs: update navigateTo utils API page
Krutie 85de469
docs: remove function from the example
Krutie a575f9f
docs: fix indentation
Krutie 9af4011
docs: fix typos
Krutie b2b8921
improvements
pi0 905d463
lint
pi0 f7ef3b1
Merge branch 'main' into pr/Krutie/5701
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,68 @@ | ||
| # `navigateTo` | ||
|
|
||
| ::ReadMore{link="/guide/features/routing"} | ||
| :: | ||
| `navigateTo` is a route helper function that allows creating programmatic navigation for users to navigate within Nuxt application. | ||
|
|
||
| `navigateTo` is available on both server side and client side. It can be used within plugins, middleware or can be called directly to perform page navigation. | ||
|
|
||
| > While using `navigateTo`, make sure to use `await` or chain its result by returning from functions. | ||
|
|
||
| ## Required parameter | ||
|
|
||
| `navigateTo` takes route as a required parameter that can be a plain string or a route object. | ||
|
|
||
| - **route:** type: string | Route | ||
|
|
||
| ### Example: Vue component | ||
|
|
||
| ```js | ||
| <script setup> | ||
| function navigate(){ | ||
| // string | ||
| return navigateTo('/search') | ||
|
|
||
| // route object | ||
| return navigateTo({ path: '/search' }) | ||
|
|
||
| // route object with query parameters | ||
| return navigateTo({ | ||
| path: '/search', | ||
| query: { | ||
| name: name.value, | ||
| type: type.value | ||
| } | ||
| }) | ||
| } | ||
| </script> | ||
| ``` | ||
|
|
||
| ## Optional parameters | ||
|
|
||
| ::NeedContribution | ||
| - **redirectCode:** type: number | ||
|
|
||
| `navigateTo` redirects to the given path and sets the redirect code to `302` by default when the redirect takes place on the server side. | ||
|
|
||
| This default behaviour can be modified by providing different `redirectCode` as an optional parameter. | ||
|
atinux marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### Example: Route middleware | ||
|
|
||
| ```js | ||
| export default defineNuxtRouteMiddleware((to, from) => { | ||
| // set the redirect code to 301 Moved Permanently | ||
| return navigateTo('/search', { redirectCode: 301 }) | ||
| }) | ||
| ``` | ||
|
|
||
| - **replace:** type: boolean | ||
|
|
||
| By default, `navigateTo` pushes the given route into Vue router instance on. | ||
|
atinux marked this conversation as resolved.
Outdated
|
||
|
|
||
| This behaviour can be changed by setting `replace` to `true`, to indicate that given route should be replaced. | ||
|
atinux marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```js | ||
| <script setup> | ||
| await navigateTo('/', { replace: true }) | ||
| </script> | ||
| ``` | ||
|
|
||
| ::ReadMore{link="/guide/features/routing"} | ||
| :: | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.