htx-ui
htx-ui

Reputation: 181

nginx/angular/node.js root URL with prerender.io

We have an angular SPA using node, nginx, and prerender.io. Our home page is set as a unique url (i.e. www.foo.com/bar) and in our routing, this home page captures the default redirect of all root-relative urls not specifically routed otherwise.

Our problem is this: the root url www.foo.com or www.foo.com/ comes back with a blank page scrape for google and Facebook. Our index is an ng-include basic template that all pages are inserted inside of, so it makes sense that our root url comes back without any real html body content. Main html in index:

<div class="st-content">
  <div ng-view="" class="main-content" id="mainView"></div>
  <div ng-include="'/views/footer.html'"></div>
</div> 

Additionally, we have tried other solutions without positive results:

Note: in writing this question it occurred to me to change the home routing to ‘/':

.when('/', {
    templateUrl: '/views/foo-bar.html',
    title: ‘Foo Bar',
    pageDescription: ‘Lorem Ipsum Foo Bar'
})
    .
    .
    .
.otherwise({
    redirectTo: '/'
});

If changed to this will the home scrape still show as blank? Isn’t this basically the same js redirect problem, but with less characters?

Upvotes: 18

Views: 920

Answers (2)

Maxime Thomasson
Maxime Thomasson

Reputation: 23

I encountered the same problem not long ago.

Do you have a code fragment that prerender.io would not be able to run?

In my case, I was using platform.js (https://github.com/bestiejs/platform.js/), and was doing a test in my appComponent.ts about "platform.name". This was not existing in Prerender.io, and I was getting a blank page.

Upvotes: 0

Karma
Karma

Reputation: 2226

You need to set the window.prerenderReady variable. Thus, put this in your route controller:

window.prerenderReady = false;

... and this in your controller's success callback function:

window.prerenderReady = true;

Upvotes: 1

Related Questions