|
1 | 1 | # V1 Meta |
2 | 2 |
|
3 | 3 | ```tsx |
4 | | -import { metaV1 } from "@remix-run/v1-meta"; |
| 4 | +import { metaV1, getMatchesData } from "@remix-run/v1-meta"; |
5 | 5 |
|
6 | | -export function meta(args) { |
| 6 | +export const meta = (args) => { |
| 7 | + // In the v1 API, `meta` received a `parentsData` argument, which is an |
| 8 | + // object keyed by each parent route ID containing the data returned by |
| 9 | + // that route's `loader` function. This argument is removed from the |
| 10 | + // v2 API. `getMatchesData` will construct an object with the same |
| 11 | + // signature, allowing you to easily refactor your code. |
| 12 | + let matchesData = getMatchesData(args); |
| 13 | + let rootData = matchesData["root"]; |
| 14 | + |
| 15 | + // This function will construct an array of `V2_MetaDescriptor` objects. |
| 16 | + // It will use the same heuristics as Remix v1 to merge the parent |
| 17 | + // route's meta values with the data you provide. |
7 | 18 | return metaV1(args, { |
8 | 19 | title: "My App", |
9 | 20 | description: "My App Description", |
10 | 21 | }); |
11 | | - // return [ |
12 | | - // { charSet: "utf-8" }, // inherited! |
13 | | - // { title: "My App" }, |
14 | | - // { name: "description", content: "My App Description" }, |
15 | | - // ]; |
16 | | -} |
| 22 | + |
| 23 | + // output: |
| 24 | + return [ |
| 25 | + // This is inherited from the parent route! |
| 26 | + { charSet: "utf-8" }, |
| 27 | + // If your parent has a title it will be overridden! |
| 28 | + { title: "My App" }, |
| 29 | + { name: "description", content: "My App Description" }, |
| 30 | + ]; |
| 31 | +}; |
17 | 32 | ``` |
0 commit comments