0

I have an Angular app that's loading in content from an API through a Python (Django) proxy. The Angular app sits on a single Django template and fetches an object every time the user interacts with a control.

I need the URL to reflect this new object every time it changes.

For example:

http://domain.com/foo/bar/apples would bring up the apples object

http://domain.com/foo/bar/oranges would bring up the oranges object

I looked into $location which seems to do the trick, but I'm having trouble getting non-html5 browsers to do what I want.

When set $locationProvider to HTML5 mode everything is great on modern browsers

HTML5

/foo/bar/apples becomes /foo/bar/oranges/ GREAT!

However, on Non-HTML5

/foo/bar/apples becomes /#!/foo/bar/oranges/ Not-Great!

Since it looks like legacy browsers require a hashbang, I'd like to move that to the latter part of the url, like so /foo/bar/#!/oranges/

If I set $location.html5Mode to false, the hashbang appears on both modern and legacy browsers (/#!/foo/bar/oranges/), but I'd like modern browsers to have non-hashbang url

Thoughts?

I'm using Angular 1.2.9

My Config:

myApp.config(['$locationProvider', function ($locationProvider) {
    $locationProvider.html5Mode(true);
}]);

On slug change, I'm calling the $locationProvider like so:

$location.path('foo/bar/' + slug);

asap
  • 5
  • 1
  • wouldn't this be more related to the server side rewrite configuration and possibly the base url set in the HTML than angular itself – Nathaniel Currier Mar 09 '14 at 21:43
  • Well, it looks like Angular is rewriting the entire URL and reloading the page. I have created a rewrite on the server to support the hash being near the right side of the url, `/foo/bar/#/slug` but `/#/foo/bar/slug/` is something angular is doing. – asap Mar 09 '14 at 23:13
  • You are going to have issues on the server anyway, because the hash fragment never get's sent to the server. – Josh Mar 10 '14 at 01:13
  • possible duplicate of [$location / switching between html5 and hashbang mode / link rewriting](http://stackoverflow.com/questions/16677528/location-switching-between-html5-and-hashbang-mode-link-rewriting) – Paul Sweatte Oct 02 '14 at 00:22

0 Answers0