mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Allow to use relative paths which starting with dot (e.g. `./[paths]`) for urls under `metadata.alternates`.
This allow user to simplify setting `canonical` or other such like `languages` once in root layout with `metadataBase` and a simple relative path, then next.js will resolve it with current pathname of the page.
For example
```js
export const metadata = {
metadataBase: new URL('https://mydomain.com'),
alternates: {
canonical: './'
}
}
```
Then:
for page `/` it will generate `https://mydomain.com`;
for page `/about` it will generate `https://mydomain.com/about`
as your cononical url
Closes NEXT-897
### Minor changes
- always remove trailing slash for `URL.href`
15 lines
253 B
TypeScript
15 lines
253 B
TypeScript
export default function layout({ children }) {
|
|
return children
|
|
}
|
|
|
|
export const metadata = {
|
|
metadataBase: 'https://example.com',
|
|
alternates: {
|
|
canonical: './',
|
|
languages: {
|
|
'en-US': './en-US',
|
|
'de-DE': './de-DE',
|
|
},
|
|
},
|
|
}
|