Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: ui-router href rewrite into ui-sref

Tags:

I have a CMS which forces URLs to pages to be of a certain pattern. We need to conditionally rewrite these link's hrefs.

The CMS will print on the page something like:

<a href="/path/to/the/zoo/gorilla.html">Go</a>

Our router needs to actually point to

#/zoo/gorilla

If we had written this link ourselves, it would look like:

<a ui-sref="zoo('gorilla')>Go</a>

The problem is, we can't always guarantee that the /zoo/gorilla part means we're at zoo('gorilla').

The easiest way would be to parse the CMS url in to the router URL and just do something like:

link.attr("href", "#/zoo/gorilla");

I understand why that is typically against the very idea of ui-router, but I'm hoping to find a way to use it for this one strange case.