Question

I have made an app with AngularJS with an expressJS backend. Now I want to make it crawlable and I've found prerender.io. I think I've done everything correct bur for some reason I don't see any statistics in the prerenderer dashboard.

In my app.configure function I've included the token like follows:

app.use(require('prerender-node').set('prerenderToken', 'my-token'));

And in my HTML I've included the meta-fragment tag:

<meta name="fragment" content="!">

The last ting I've done was to tell AngularJS to use a hashprefix:

$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');

But for some reason, if I refer to the documentation, I don't get the correct result. Below you can see what it is supposed to do:

Google sends a request to your server like this:

http://www.example.com/?_escaped_fragment_=/user/123

You turn the url back into this:

http://www.example.com/#!/user/123

For some reason if I try this it still adds the #! signs add the end of the URL, so if I request the URL of my app like google I get this:

http://www.my-website.com/?_escaped_fragment_=#!/home

So it does not replace the hash in the url. I think this is the cause of my problem.

Thanks in advance!

Edit - if I for example add an extra route then it works:

app.get('/', function (req, res) {
    res.sendfile('./public/index.html'); 
});

app.get('/test', function (req, res) {
    res.sendfile('./public/index.html'); 
});

the '/' route doesn't work the '/test' route does work.

Was it helpful?

Solution

Ok I solved my problem. The '/' route was never called because I had an index.html file inside my webpublic folder. I renamed this to public.html and changed the '/' route to get this file instead of the index.html file.

app.get('/', function (req, res) {
    res.sendfile('./public/public.html');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top