How to make Disqus to work with url routing?

2019-09-06 00:02发布

问题:

SOLVED

I have a default Disqus code pasted on my site:

...

var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};

...

And my site is using polymer routing ( I have one html file with <section></section> for each page )

And as a routing I have this:

...
      page('/contact', function() {
        app.route = 'contact';
        setFocus(app.route);
        ga('set', 'page', '/contact');
        ga('send', 'pageview');
    });

      page('/privacy_policy', function() {
        app.route = 'privacy_policy';
        setFocus(app.route);
        ga('set', 'page', '/privacy_policy');
        ga('send', 'pageview');
    });
...

for each page.

Disqus is not working properly, when I open the Disqus admin panel itis only showing me a link to my comment for {{baseurl}}.com url even though I left a comment from baseurl.com/page/

What should I put instead of:

this.page.url = PAGE_URL; 
this.page.identifier = PAGE_IDENTIFIER; 

I can't figure out how to put app.route = 'contact'; there, because this.page.url = app.route = 'contact'; structure doesn't make sense, and I can't put the direct link there since https:// - will open a comment in the code.

回答1:

SOLVED IT:

To resolve this problem just replace

var disqus_config = function () {
this.page.url = PAGE_URL;
this.page.identifier = PAGE_IDENTIFIER; 
};

with

var disqus_config = function () {
this.page.url = 'https://www.YourSiteName.com/YourRoutePageName';
this.page.identifier = 'SomeUniqueIdGoesHere';
};

Notice the https there. If you don't use https, just put http instead

For more on this, read https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables