React framework
Add automatic MyOG.social images to React Router Framework Mode routes with meta exports, loaders, and pre-rendered or server-rendered HTML.
React Router Framework Mode renders route metadata from each route module's meta export.
MyOG works best when those meta descriptors are present in the initial HTML response, so social crawlers can read og:image without running client-side JavaScript.
Use loader data or route params to build the canonical page URL, then return Open Graph and Twitter image descriptors from meta.
MyOG detects page content and branding automatically. The layout only controls image composition.
Use this in a public Framework Mode route module.
import type { MetaFunction } from "react-router";
export const meta: MetaFunction = () => {
return [
{ property: "og:image", content: "https://api.myog.social/og?url=https%3A%2F%2Fexample.com%2Fblog%2Fmy-post&template=screenshot-right" },
{ property: "og:image:width", content: "1200" },
{ property: "og:image:height", content: "630" },
{ name: "twitter:card", content: "summary_large_image" },
{ name: "twitter:image", content: "https://api.myog.social/og?url=https%3A%2F%2Fexample.com%2Fblog%2Fmy-post&template=screenshot-right" },
];
};Replace the encoded example URL with the route's final canonical URL.
Use loader data when the canonical URL depends on route params or content records.
import type { LoaderFunctionArgs, MetaFunction } from "react-router";
export async function loader({ params }: LoaderFunctionArgs) {
const post = await getPost(params.slug);
return {
title: post.title,
canonicalURL: `https://example.com/blog/${post.slug}`,
};
}
export const meta: MetaFunction<typeof loader> = ({ data }) => {
const pageURL = encodeURIComponent(data?.canonicalURL ?? "https://example.com");
const imageURL = `https://api.myog.social/og?url=${pageURL}&template=screenshot-right`;
return [
{ title: data?.title ?? "Blog post" },
{ property: "og:image", content: imageURL },
{ property: "og:image:width", content: "1200" },
{ property: "og:image:height", content: "630" },
{ name: "twitter:card", content: "summary_large_image" },
{ name: "twitter:image", content: imageURL },
];
};Keep the canonical URL stable across trailing slashes, locale prefixes, and redirects.
If your root route, parent route, or SEO helper already returns og:image, merge metadata carefully and keep only one preferred image for a page. React Router nested routes can override or replace parent metadata depending on how your meta functions are composed.
Dynamic routes should build the MyOG url parameter from the final canonical URL, not from a client-side location value. Use loader data for slugs, locale prefixes, or canonical aliases when the request path is not the URL you want shared.
Start with the MyOG Open Graph Checker, then refresh social platform caches if needed.
Sign up for free and add generated social images to React Router routes.
Already have an account?
cdf733b534ea2f2ed964d150330b323c44837e4f