From be99c17c2901b9c2a6cc5c374dca851b3598a462 Mon Sep 17 00:00:00 2001 From: Krutie Patel Date: Mon, 4 Jul 2022 00:51:43 +1000 Subject: [PATCH 1/6] docs: update navigateTo utils API page --- docs/content/3.api/3.utils/navigate-to.md | 67 ++++++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/docs/content/3.api/3.utils/navigate-to.md b/docs/content/3.api/3.utils/navigate-to.md index c65a8b8427c..8cba03703a3 100644 --- a/docs/content/3.api/3.utils/navigate-to.md +++ b/docs/content/3.api/3.utils/navigate-to.md @@ -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 + +``` + +## 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. + +### 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. + +This behaviour can be changed by setting `replace` to `true`, to indicate that given route should be replaced. + +```js + +``` + +::ReadMore{link="/guide/features/routing"} :: From 85de469621ec57c45daf13c5556988a3b8aac4ac Mon Sep 17 00:00:00 2001 From: Krutie Patel Date: Mon, 4 Jul 2022 09:11:26 +1000 Subject: [PATCH 2/6] docs: remove function from the example --- docs/content/3.api/3.utils/navigate-to.md | 32 +++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/content/3.api/3.utils/navigate-to.md b/docs/content/3.api/3.utils/navigate-to.md index 8cba03703a3..c9e6f684115 100644 --- a/docs/content/3.api/3.utils/navigate-to.md +++ b/docs/content/3.api/3.utils/navigate-to.md @@ -15,23 +15,21 @@ ### Example: Vue component ```js - ``` From a575f9f4ae2242b55c9607463d942ffe2a6d3e4a Mon Sep 17 00:00:00 2001 From: Krutie Patel Date: Mon, 4 Jul 2022 10:36:46 +1000 Subject: [PATCH 3/6] docs: fix indentation --- docs/content/3.api/3.utils/navigate-to.md | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/content/3.api/3.utils/navigate-to.md b/docs/content/3.api/3.utils/navigate-to.md index c9e6f684115..0da5a15150b 100644 --- a/docs/content/3.api/3.utils/navigate-to.md +++ b/docs/content/3.api/3.utils/navigate-to.md @@ -16,20 +16,20 @@ ```js ``` From 9af40111cc3be190f620454bb1488d8ad5271ded Mon Sep 17 00:00:00 2001 From: Krutie Patel Date: Mon, 4 Jul 2022 23:09:49 +1000 Subject: [PATCH 4/6] docs: fix typos --- docs/content/3.api/3.utils/navigate-to.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/content/3.api/3.utils/navigate-to.md b/docs/content/3.api/3.utils/navigate-to.md index 0da5a15150b..1a6e1ddb3ce 100644 --- a/docs/content/3.api/3.utils/navigate-to.md +++ b/docs/content/3.api/3.utils/navigate-to.md @@ -39,7 +39,7 @@ return navigateTo({ `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. +This default behavior can be modified by providing different `redirectCode` as an optional parameter. ### Example: Route middleware @@ -52,9 +52,9 @@ export default defineNuxtRouteMiddleware((to, from) => { - **replace:** type: boolean -By default, `navigateTo` pushes the given route into Vue router instance on. +By default, `navigateTo` pushes the given route into Vue router instance. -This behaviour can be changed by setting `replace` to `true`, to indicate that given route should be replaced. +This behavior can be changed by setting `replace` to `true`, to indicate that given route should be replaced. ```js ``` -## Optional parameters - -- **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 behavior can be modified by providing different `redirectCode` as an optional parameter. - -### Example: Route middleware +### Within route middleware ```js export default defineNuxtRouteMiddleware((to, from) => { @@ -50,17 +50,32 @@ export default defineNuxtRouteMiddleware((to, from) => { }) ``` -- **replace:** type: boolean - -By default, `navigateTo` pushes the given route into Vue router instance. - -This behavior can be changed by setting `replace` to `true`, to indicate that given route should be replaced. - ```js ``` -::ReadMore{link="/guide/features/routing"} +::ReadMore{link="/guide/directory-structure/middleware"} :: + + +### Options + +#### `redirectCode` + +- Type: Number + +`navigateTo` redirects to the given path and sets the redirect code to [`302` Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302) by default when the redirect takes place on the server side. + +This default behavior can be modified by providing different `redirectCode` as an optional parameter. Commonly [`301` Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301) can be used for permant redirections. + + +#### `replace` + +- Type: Boolean + +By default, `navigateTo` pushes the given route into Vue router instance on client-side. + +This behavior can be changed by setting `replace` to `true`, to indicate that given route should be replaced. + From 905d463991e750780738f3d7ec92902ec3b4c60f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 7 Jul 2022 20:46:50 +0200 Subject: [PATCH 6/6] lint --- docs/content/2.guide/3.directory-structure/7.middleware.md | 1 - docs/content/3.api/3.utils/navigate-to.md | 5 ----- 2 files changed, 6 deletions(-) diff --git a/docs/content/2.guide/3.directory-structure/7.middleware.md b/docs/content/2.guide/3.directory-structure/7.middleware.md index db0042b7468..d25d3249833 100644 --- a/docs/content/2.guide/3.directory-structure/7.middleware.md +++ b/docs/content/2.guide/3.directory-structure/7.middleware.md @@ -56,7 +56,6 @@ Unlike navigation guards in [the vue-router docs](https://router.vuejs.org/guide ::ReadMore{link="/guide/features/routing"} :: - ::alert{type=warning} We recommend using the helper functions above for performing redirects or stopping navigation. Other possible return values described in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards) may work but there may be breaking changes in future. :: diff --git a/docs/content/3.api/3.utils/navigate-to.md b/docs/content/3.api/3.utils/navigate-to.md index fffe89da448..636e3e5990b 100644 --- a/docs/content/3.api/3.utils/navigate-to.md +++ b/docs/content/3.api/3.utils/navigate-to.md @@ -4,7 +4,6 @@ `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. - ## Usage ```ts @@ -40,7 +39,6 @@ return navigateTo({ ``` - ### Within route middleware ```js @@ -59,7 +57,6 @@ export default defineNuxtRouteMiddleware((to, from) => { ::ReadMore{link="/guide/directory-structure/middleware"} :: - ### Options #### `redirectCode` @@ -70,7 +67,6 @@ export default defineNuxtRouteMiddleware((to, from) => { This default behavior can be modified by providing different `redirectCode` as an optional parameter. Commonly [`301` Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301) can be used for permant redirections. - #### `replace` - Type: Boolean @@ -78,4 +74,3 @@ This default behavior can be modified by providing different `redirectCode` as a By default, `navigateTo` pushes the given route into Vue router instance on client-side. This behavior can be changed by setting `replace` to `true`, to indicate that given route should be replaced. -