Home:ALL Converter>Use Angular routing alongside roundtrip routing

Use Angular routing alongside roundtrip routing

Ask Time:2013-06-26T19:25:44         Author:Nat

Json Formatter

I'm working on a Django app which makes heavy use of Angular in some pages, e.g. at domain.com/myAngularApp

Within the angular page I'm using Angular routing for navigating between different views/states within that page. However across the whole website there are navigation links which need to result in round trip requests to Django. However all the pages include the same compiled javascript file which includes the Angular route declarations.

So my question is: how to I get Angular to mange its own routes and get out of the way when the location is changed (primarily by clicking a link on the page) to a path that it hasn't explicitly been told to own, i.e. to different subdirectories off the domain.

My routing declaration looks something like:

myApp.config( function($locationProvider, $routeProvider) {
  $locationProvider.html5Mode(true);
  $routeProvider.when('/myAngularApp/', {
    templateURL: 'template1.html'
  });
  $routeProvider.when('/myAngularApp/stuff', {
    templateURL: 'template12.html'
  });
  $routeProvider.otherwise({redirectTo:  <not sure what to do here...>  });
})

I've tried something like:

$routeProvider.otherwise({redirectTo: function(a1,r,a3){ window.location.href = r }})

But this makes the page refresh endlessly on any non-matched route.

Leaving out the otherwise statement seems to make it impossible to leave a page with a non-matched route when accessed directly... don't really understand why?

It must be possible to do what I want no?

Author:Nat,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/17318746/use-angular-routing-alongside-roundtrip-routing
yy