navigateTo is available on both server side and client side. It can be used within the Nuxt context, or directly, to perform page navigation.
await or return on result of navigateTo when calling it.navigateTo cannot be used within Nitro routes. To perform a server-side redirect in Nitro routes, use sendRedirect instead.<script setup lang="ts">
// passing 'to' as a string
await navigateTo('/search')
// ... or as a route object
await navigateTo({ path: '/search' })
// ... or as a route object with query parameters
await navigateTo({
  path: '/search',
  query: {
    page: 1,
    sort: 'asc',
  },
})
</script>
export default defineNuxtRouteMiddleware((to, from) => {
  if (to.path !== '/search') {
    // setting the redirect code to '301 Moved Permanently'
    return navigateTo('/search', { redirectCode: 301 })
  }
})
When using navigateTo within route middleware, you must return its result to ensure the middleware execution flow works correctly.
For example, the following implementation will not work as expected:
export default defineNuxtRouteMiddleware((to, from) => {
  if (to.path !== '/search') {
    // ❌ This will not work as expected
    navigateTo('/search', { redirectCode: 301 })
    return
  }
})
In this case, navigateTo will be executed but not returned, which may lead to unexpected behavior.
The external parameter in navigateTo influences how navigating to URLs is handled:
external: true:external: true:<script setup lang="ts">
// will throw an error;
// navigating to an external URL is not allowed by default
await navigateTo('https://nuxt.com')
// will redirect successfully with the 'external' parameter set to 'true'
await navigateTo('https://nuxt.com', {
  external: true,
})
</script>
<script setup lang="ts">
// will open 'https://nuxt.com' in a new tab
await navigateTo('https://nuxt.com', {
  open: {
    target: '_blank',
    windowFeatures: {
      width: 500,
      height: 500,
    },
  },
})
</script>
export function navigateTo (
  to: RouteLocationRaw | undefined | null,
  options?: NavigateToOptions
): Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw
interface NavigateToOptions {
  replace?: boolean
  redirectCode?: number
  external?: boolean
  open?: OpenOptions
}
type OpenOptions = {
  target: string
  windowFeatures?: OpenWindowFeatures
}
type OpenWindowFeatures = {
  popup?: boolean
  noopener?: boolean
  noreferrer?: boolean
} & XOR<{ width?: number }, { innerWidth?: number }>
  & XOR<{ height?: number }, { innerHeight?: number }>
  & XOR<{ left?: number }, { screenX?: number }>
  & XOR<{ top?: number }, { screenY?: number }>
toType: RouteLocationRaw | undefined | null
Default: '/'
to can be a plain string or a route object to redirect to. When passed as undefined or null, it will default to '/'.
// Passing the URL directly will redirect to the '/blog' page
await navigateTo('/blog')
// Using the route object, will redirect to the route with the name 'blog'
await navigateTo({ name: 'blog' })
// Redirects to the 'product' route while passing a parameter (id = 1) using the route object.
await navigateTo({ name: 'product', params: { id: 1 } })
options (optional)Type: NavigateToOptions
An object accepting the following properties:
replacebooleanfalsenavigateTo pushes the given route into the Vue Router's instance on the client side.replace to true, to indicate that given route should be replaced.redirectCodenumber302navigateTo redirects to the given path and sets the redirect code to 302 Found by default when the redirection takes place on the server side.redirectCode. Commonly, 301 Moved Permanently can be used for permanent redirections.externalbooleanfalsetrue. Otherwise, navigateTo will throw an error, as external navigation is not allowed by default.openOpenOptionstargetstring'_blank'windowFeaturesOpenWindowFeatures| Property | Type | Description | 
|---|---|---|
| popup | boolean | Requests a minimal popup window instead of a new tab, with UI features decided by the browser. | 
| widthorinnerWidth | number | Specifies the content area's width (minimum 100 pixels), including scrollbars. | 
| heightorinnerHeight | number | Specifies the content area's height (minimum 100 pixels), including scrollbars. | 
| leftorscreenX | number | Sets the horizontal position of the new window relative to the left edge of the screen. | 
| toporscreenY | number | Sets the vertical position of the new window relative to the top edge of the screen. | 
| noopener | boolean | Prevents the new window from accessing the originating window via window.opener. | 
| noreferrer | boolean | Prevents the Referer header from being sent and implicitly enables noopener. |