Facebook Open Graph Single Page Apps

2019-02-15 08:38发布

问题:

I have built a single page application using backbone js. I have separate backbone url "routes" for various application states and dynamic content (e.g. books), but essentially Facebook will only ever see the index page.

The following SO question seems to provide an interesting approach to providing physical open graph URLs for dynamic content:

Multiple Facebook opengraph objects on the same page

How have other developers approached using open graph tags on dynamic pages, specifically in single page apps?

回答1:

You can have the server output dynamic content for this, but you still need a different url for each object since this is how facebook index those objects.

What you can do however, is use the querystring or fragment parts of the url to identify it. So, let's say you have a single page that you want to serve all the open graph objects: your-domain.com/og now you can add to it identifiers like this:

your-domain.com/og?type=3&id=432543643
your-domain.com/og#type=653&id=46t43g3
your-domain.com/og?type=25id=4tn4g43#anotherstring