Ad

Issue With Prerender.io Always Rendering The Default Angular Route For A List Of Client Side Routes

- 1 answer

Just want to say I really like prerender.io, but I am currently having an issue with it and I am wondering if maybe I am doing something wrong and people with more experience with the service can help me out.

I am having the same issue with the prerender.io site and also with a Debian Linux box I setup with prerender for local execution.

My new site is a hybrid of ASP.Net MVC and angular, where angular represents workflows (or categories of content) within MVC routes on the server.

An example of a category of content is this:

http://[somesitename]/PublicContent/#!/news

http://[somesitename]/PublicContent/#!/welcome

The MVC server side route is:

http://[somesitename]/PublicContent

and #!/news and #!/welcome are the angular app routes and welcome is also the default route.

When I send my URL to the prerender.io service or my local instance:

http://service.prerender.io/http://[somesitename]/PublicContent/#!/news

The prerender service is only ever rendering:

http://[somesitename]/PublicContent

and is ignoring the client side route after the #!

so for all my pages for each MVC route I am merely getting the default route rendered multiple times...

Is this a bug with prerender.io? Or do I not have something not properly configurered?

I do have the:

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

in the head for all my pages if that would matter.

Ad

Answer

Talked with the guys over at prerender.io, and it appears that a modification I made to the Asp.Net MVC middleware where it was removing ?_escpaed_fragment_=/ completely was an incorrect modification to this code, which itself was incorrect (the base code removed ?_escpaed_fragment_=/ and replaced it with nothing, I modified the code to remove ?_escpaed_fragment_=/ and replace it with #!).

The prerender.io service expected ?_escpaed_fragment_=/ to exist in the URL and if it finds it it will replace it with #! before calling your website to cache the page. It doesn't expect to find the #!, so it won't properly process the URL if it is there.

So if you are using the Asp.Net MVC middleware you should comment out the following code from PrerenderModule.cs:

        // Remove the _escaped_fragment_ from the URL if it exists!
        var escapedFull = "?" + _Escaped_Fragment + "=/";
        if (url.Contains(escapedFull))
        {
            url = url.Replace(escapedFull, string.Empty);
        }
Ad
source: stackoverflow.com
Ad