Courses developed in collaboration with @nuxt.com
Powered by @bitterbrains.com
When you want to create a redirect in a server route, Nuxt lets you use the `sendRedirect` method from h3.
By default, this sends a 302 (temporary) redirect, but you can specify a different status code if needed.
When you want to create a redirect in a server route, Nuxt lets you use the `sendRedirect` method from h3.
By default, this sends a 302 (temporary) redirect, but you can specify a different status code if needed.
With Nuxt, since version 3.9, you can control how fetch requests are deduplicated using the dedupe parameter in the useFetch composable.
By setting dedupe to 'cancel', the previous request is cancelled and a new one is made whenever parameters change.
With Nuxt, since version 3.9, you can control how fetch requests are deduplicated using the dedupe parameter in the useFetch composable.
By setting dedupe to 'cancel', the previous request is cancelled and a new one is made whenever parameters change.
With Nuxt, you can access the entire payload sent from the server to the client using the useNuxtApp composable.
This allows you to inspect all the data and state transferred during SSR or hydration.
With Nuxt, you can access the entire payload sent from the server to the client using the useNuxtApp composable.
This allows you to inspect all the data and state transferred during SSR or hydration.
This allows you to inspect all the data and state transferred during SSR or hydration.
This allows you to inspect all the data and state transferred during SSR or hydration.
When working with Nuxt, you can control where your code runs by checking the environment. Use if (!import.meta.server) to skip code on the server, and if (!import.meta.client) to skip code on the client.
When working with Nuxt, you can control where your code runs by checking the environment. Use if (!import.meta.server) to skip code on the server, and if (!import.meta.client) to skip code on the client.
For example, you can name your test file like this 👇
For example, you can name your test file like this 👇
In Nuxt you can pass route objects to `navigateTo`, similar to `router.push` in Vue Router.
This enables navigation using named routes, query parameters, or hash fragments.
In Nuxt you can pass route objects to `navigateTo`, similar to `router.push` in Vue Router.
This enables navigation using named routes, query parameters, or hash fragments.
To do this, wrap your component with a `<DevOnly>` tag in your layout file. This component will be excluded from your production build.
To do this, wrap your component with a `<DevOnly>` tag in your layout file. This component will be excluded from your production build.
This lets you manipulate the DOM or add event listeners using only vanilla JavaScript:
This lets you manipulate the DOM or add event listeners using only vanilla JavaScript:
We can do that with useRequestHeaders (or useRequestHeader):
We can do that with useRequestHeaders (or useRequestHeader):
Modules can only affect your Nuxt app during build time.
But we can use methods from @nuxt/kit to do things that influence the runtime behaviour:
Modules can only affect your Nuxt app during build time.
But we can use methods from @nuxt/kit to do things that influence the runtime behaviour:
You can define a redirect for any route, and by default, it uses a temporary 307 status code. This is the simplest & most efficient way to handle basic redirects.
You can define a redirect for any route, and by default, it uses a temporary 307 status code. This is the simplest & most efficient way to handle basic redirects.
You can specify this class using the `prefetched-class` prop, which helps you visually identify prefetched links during development.
You can specify this class using the `prefetched-class` prop, which helps you visually identify prefetched links during development.
In Nuxt, you can validate the request body before using it by leveraging readValidatedBody from h3. Provide a validation function to ensure the body meets your requirements.
In Nuxt, you can validate the request body before using it by leveraging readValidatedBody from h3. Provide a validation function to ensure the body meets your requirements.
In Nuxt, you can check for specific error codes like 404 using the statusCode property from the useError composable. This lets you show a custom message for not found pages, while handling other errors differently.
In Nuxt, you can check for specific error codes like 404 using the statusCode property from the useError composable. This lets you show a custom message for not found pages, while handling other errors differently.
This is useful for testing route-specific content or behavior in your Nuxt application.
This is useful for testing route-specific content or behavior in your Nuxt application.
For example, to add a custom folder for global components:
For example, to add a custom folder for global components:
Within Nuxt, the `useLoadingIndicator` composable is used by the `<NuxtLoadingIndicator>` component.
You can also trigger it manually in plugins using the `page:loading:start` and `page:loading:end` hooks.
Within Nuxt, the `useLoadingIndicator` composable is used by the `<NuxtLoadingIndicator>` component.
You can also trigger it manually in plugins using the `page:loading:start` and `page:loading:end` hooks.
This utility lets you sync data between server and client by using hooks and the Nuxt payload system.
This utility lets you sync data between server and client by using hooks and the Nuxt payload system.
It provides reactive values like `progress` and `isLoading`, which can be logged or used in your UI.
It provides reactive values like `progress` and `isLoading`, which can be logged or used in your UI.
With Nuxt, you can have different `nuxt.config.ts` files for each layer, allowing each part of your app to have its own configuration.
For example, your main app and a blog layer can each have their own config files with different modules and settings.
With Nuxt, you can have different `nuxt.config.ts` files for each layer, allowing each part of your app to have its own configuration.
For example, your main app and a blog layer can each have their own config files with different modules and settings.
With Nuxt, you can use layers to provide child or parent routes seamlessly. By placing files inside nested folders within a layer's pages directory, you can create child routes that integrate naturally with your main app's routes:
With Nuxt, you can use layers to provide child or parent routes seamlessly. By placing files inside nested folders within a layer's pages directory, you can create child routes that integrate naturally with your main app's routes: