Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs ui-router blocking access to non-state routes

I am using ui-router in an angular site I'm making, but cant get it to allow routes through to my server. I have facebook oauth authentication on my server, where I navigate to /auth/facebookand the server will redirect to fb, intercept the callback and redirect the client back to the homepage.

It works fine when navigating to the /auth/facebook url in a browser it works fine, but ui-router watches location and intercepts all of my location changes.

Any ideas how I can make a url request bypass the $urlRouterProvider.otherwise(...) statement to allow a route through to my api server? I've tried adding route redirects with the router provider, but it won't trigger a remote call.

like image 414
mrosales Avatar asked Jun 24 '14 03:06

mrosales


2 Answers

Thanks to the guys at angular-dart: As a workaround you could create an ng-click handler that does window.location.assign('/auth/facebook') to bypass the router

like image 174
Jorg Avatar answered Nov 07 '22 17:11

Jorg


You can handle such requests in your app config with $urlRouterProvider:

$urlRouterProvider.when('/auth/:provider', function() {
  window.location.reload();
});

Second solution: Add target="_self" to your link like this:

<a target="_self" ng-href="{{'/auth/'+provider}}">{{provider}}</a>

Duplicate of: angular.js link behaviour - disable deep linking for specific URLs

like image 3
Betty St Avatar answered Nov 07 '22 16:11

Betty St