og meta tags, social buttons and angularjs

前端 未结 2 396
予麋鹿
予麋鹿 2020-12-01 06:54

I\'m creating a website using multiple views. The tag and the tags of the page get changed through a a $rootScope variable. so I have something like



        
2条回答
  •  失恋的感觉
    2020-12-01 07:15

    This can't be done using javascript. Some people think that Facebook is reading what's currently on the page. It's not. It makes a separate request to your server using the same url (from window.location.href) using it's Scraper, and the Facebook Scraper does not run javascript. That's why you get {{page_title}} when clicking on something like a Facebook share button. Your content will have to be generated by the server so when Facebook goes to hit the url it gets the content it needs up front without the need for javascript. You can tackle the server side rendering in a fews ways.

    1. You can allow your server side technology to render the content.
    2. You can use the PhantomJS approach https://github.com/steeve/angular-seo.

提交回复
热议问题