Tuesday, July 7, 2015

Angular JS $state.go redirects to home page


$urlRouterProvider.otherwise() called before $state.go()


i faced above problem in one of my application. I needed to change the state on click event of anchor tag. User was being navigated to Otherwise route rather than redirecting to the route that was called on click event. following was my code,

<a ng-click="SetClient(Name)" href="#">{{Name}}</a>

function SetClient(stateName)

The following configuration is used for redirection if any other url is provided.

The Problem

When ever i clicked on the hyperlink, it redirected to home state rather than the state name that was passed to SetClient.


I found out that "#" hash sign is creating problem. i removed hash sign and it worked fine.
<a ng-click="SetClient(Name)" href>{{Name}}</a>
Hash sign was calling "$urlRouterProvider.otherwise".

No comments:

Post a Comment