You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/seo.md
+86-8Lines changed: 86 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,92 @@
1
1
# SEO
2
2
3
-
With `seo` option enabled, **nuxt-i18n** attempts to add some metadata to improve your pages SEO. Here's what it does:
4
3
5
-
* Add a _lang_ attribute containing current locale's ISO code to the `<html>` tag.
6
-
* Generate `<link rel="alternate" hreflang="x">` tags for every language configured in `nuxt.config.js`. For each language, the ISO code is used as `hreflang` attribute's value. [More on hreflang](https://support.google.com/webmasters/answer/189077)
7
-
* Generate `og:locale` and `og:locale:alternate` meta tags as defined in the [Open Graph protocol](http://ogp.me/#optional)
8
-
* When using `prefix_and_default` strategy, generate `rel="canonical"` link on the default language routes containing the
4
+
## Benefits
5
+
6
+
When the `seo` option is enabled, **nuxt-i18n** attempts to add some metadata to improve your pages SEO. Here's what it does.
7
+
8
+
### `lang` attribute for `<html>` tag.
9
+
10
+
With `seo` enabled, nuxt-i18n will set the correct `lang` attribute, equivalent to the current locale's ISO code, in the `<html>` tag.
11
+
12
+
### Automatic hreflang generation
13
+
14
+
nuxt-i18n will generate `<link rel="alternate" hreflang="x">` tags for every language configured in `nuxt.config.js`.
15
+
The language's ISO codes are used as `hreflang` values.
16
+
17
+
Since version [v6.6.0](https://github.com/nuxt-community/nuxt-i18n/releases/tag/v6.6.0), a catchall locale hreflang link
18
+
is provided for each language group (e.g. `en-*`) as well.
19
+
By default, it is the first language provided but another language can be selected by setting `isCatchallLocale` to `true`
20
+
on that specific language object in your `nuxt.config.js`. [More on hreflang](https://support.google.com/webmasters/answer/189077)
21
+
22
+
An example without selected catchall locale:
23
+
```js
24
+
// nuxt.config.js
25
+
26
+
['nuxt-i18n', {
27
+
locales: [
28
+
{
29
+
code:'en',
30
+
iso:'en-US'// Will be used as catchall locale by default
31
+
},
32
+
{
33
+
code:'gb',
34
+
iso:'en-GB'
35
+
}
36
+
]
37
+
}]
38
+
```
39
+
40
+
Here is how you'd use `isCatchallLocale` to selected another language:
41
+
```js
42
+
// nuxt.config.js
43
+
44
+
['nuxt-i18n', {
45
+
locales: [
46
+
{
47
+
code:'en',
48
+
iso:'en-US'
49
+
},
50
+
{
51
+
code:'gb',
52
+
iso:'en-GB',
53
+
isCatchallLocale:true// This one will be used as catchall locale
54
+
}
55
+
]
56
+
}]
57
+
```
58
+
59
+
In case you already have an `en` language iso set, it'll be used as the catchall without doing anything
60
+
61
+
```js
62
+
// nuxt.config.js
63
+
64
+
['nuxt-i18n', {
65
+
locales: [
66
+
{
67
+
code:'gb',
68
+
iso:'en-GB'
69
+
},
70
+
{
71
+
code:'en',
72
+
iso:'en'// will be used as catchall locale
73
+
}
74
+
]
75
+
}]
76
+
```
77
+
78
+
### OpenGraph Locale tag generation
79
+
80
+
nuxt-i18n will also generate `og:locale` and `og:locale:alternate` meta tags as defined in the [Open Graph protocol](http://ogp.me/#optional).
81
+
82
+
### Canonical links for `prefix_and_default`
83
+
84
+
When using the `prefix_and_default` strategy, `rel="canonical"` links on the default language routes will be generated and contain the
9
85
prefix to avoid duplicate indexation. [More on canonical](https://support.google.com/webmasters/answer/182192#dup-content)
10
86
87
+
## Requirements
11
88
12
-
For this feature to work, you must configure `locales` option as an array of objects, where each object has an `iso` option set to the language ISO code:
89
+
To leverage the SEO benefits of nuxt-i18n, you must configure the `locales` option as an array of objects, where each object has an `iso` option set to the language's ISO code:
13
90
14
91
```js
15
92
// nuxt.config.js
@@ -32,7 +109,7 @@ For this feature to work, you must configure `locales` option as an array of obj
32
109
}]
33
110
```
34
111
35
-
You should also set the `baseUrl` option to your production domain in order to make alternate URLs fully-qualified:
112
+
You must also set the `baseUrl` option to your production domain in order to make alternate URLs fully-qualified:
36
113
37
114
```js
38
115
// nuxt.config.js
@@ -43,7 +120,8 @@ You should also set the `baseUrl` option to your production domain in order to m
43
120
```
44
121
45
122
46
-
To enable this feature everywhere in your app, set `seo` option to `true`:
123
+
To enable this feature everywhere in your app, set `seo` option to `true`.
124
+
**This comes with a performance drawback though**. More information below.
0 commit comments