Redirections
In some situations, you want to redirect a page to another page. It can be useful when you change the url of a page, or when you want to redirect a page to another domain.
To do so, you can:
- add a
redirect_to_full_url
field to the frontmatter of the page you want to redirect. The value of this field should be the full url of the page you want to redirect to. - add a
redirect_to_domain
field to the frontmatter of the page you want to redirect. The value of this field should be the domain of the page you want to redirect to. The page will be redirected to the same path on the new domain.
Example:
---
hidden: true
redirect_to_full_url: "https://www.example.com/2024/01/my-new-page"
---
However, if you use hidden: true
in your page, and no internal link leads to it, it won't be created at static generation time.
So, instead of a redirect, you'll have a 404 error.
To avoid this, You have to explicitely list your page in the page to be prerenedered in the nuxt.config.js
file.
Example:
nitro: {
prerender: {
routes: [
"/2024/01/my-new-page",
"/url2",
"/url3",
// ...
]
}
}