Adding hreflang alternate links in head
See original GitHub issueI’m trying to automatically add the hreflang links in the head but it’s not that easy.
I moved the locales array outside of the module.exports
and added the following code in thenuxt.config.js
file and it kinda works:
const locales = [
{ code: 'en', ... },
{ code: 'fr', ... }
]
module.exports = {
...
head: {
link: [
...
].concat((function () {
let alternates = []
locales.forEach((locale) => {
alternates.push({
hid: `alternate-${locale.code}`,
rel: 'alternate',
hreflang: locale.code,
href: `https://example.com/${locale.code}`
})
})
return alternates
})())
}
}
However, I didn’t find a way to dynamically change the href
value. The method switchLocalePath()
is not accessible from the nuxt.config.js
file and it seems we can’t access to this.$route.name
too.
Any idea on how to do that? What about nuxt-i18n
injecting theses alternate links by default since Nuxt is sold as SEO-friendly out of the box. It would be a great addition to the module.
Finally an unrelated question. Why nuxt-i18n is not a scoped package like the sitemap module for instance @nuxtjs/sitemap
?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:11
Top Results From Across the Web
Hreflang: The Easy Guide for Beginners - Ahrefs
To implement hreflang tags correctly for this setup, we'd add this code to the <head> section of each of our pages: <link rel="alternate" ......
Read more >Dynamically add a link tag to the page head section with ...
1. One of the options is to add the links or the link in the head section of the pages manually. · 2....
Read more >What are Hreflang Tag Attributes And How To Implement Them
Introduced by Google in December 2011, the hreflang attribute allows you to show search engines what the relationship is between web pages in...
Read more >hreflang: the ultimate guide • Yoast
This guide discusses what hreflang is, what it is for and gives in-depth information on how to implement it for your multilingual websites....
Read more >How to Add Hreflang Tags (Without Breaking Your SEO)
Many people use hreflang tags wrong, and that's bad news for your SEO. Our clear guide shows you how to add them correctly....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@paulgv This is a serious issue not just because of the broken tags but also because it generates thousands of warnings which really causes high cpu usage and makes the app slow.
Ok, I think I found a solution to the problem, in
layouts
, indefault.vue
we create a base head for our application and take the fields with this.$nuxtI18nSeo():This option will dynamically create links, so far I see the solution to this problem like this.Hope helped.