Durandal 2.0 router can you replace # for #! for ajax web crawling purposes? Durandal 2.0 router can you replace # for #! for ajax web crawling purposes? ajax ajax

Durandal 2.0 router can you replace # for #! for ajax web crawling purposes?


As far as I know, in Durandal 2.0 you are not able to do this. The router and history plugin do not support this, and it would not be an easy fix since there are some places in the code that rely on the #.

However, I don't think this is a problem in your scenario. Maybe you need to change the way to deal with the requirement of making your application crawlable.

You still can make your application SEO compatible using #by specifying the meta fragment type in the main HTML of the application:

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

So you are telling google that your links don't have the #!but that the application is using JavaScript rendering. Then the requests from the crawler will include ?_escaped_fragment_.

So in your app you will use:

mysite.com/#myroute

and the crawler will request:

mysite.com?_escaped_fragment_=myroute

Check the Section 3 of Google's documentation on crawling to know more about the meta fragment tag.

SUGGESTION

If you want to fully take advantage of this feature I suggest using pushState in Durandal 2.0 by activating the router like this:

router.activate({ pushState: true } );

And also including the meta fragment tag.

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

Things you should consider if using pushState:

  • Use pushState only if you are not planning to support old browsers.

  • You need to make your server side pushState ready, this means that when the server is requested with mysite.com/myrouteshould be able to return the same JS application and let the client process the query string parameters. For example, this can be achieved using IIS URL rewrite if you are using ASP.NET. There's a good blog post about this topic.