Changing $location's baseHref without adding a <base /> tag

384 views
Skip to first unread message

Oz Michaeli

unread,
Feb 12, 2013, 4:34:59 PM2/12/13
to ang...@googlegroups.com
After reading up as much as I could on this topic, and making sure to keep in mind Angular's 'zen' rules, I'd like to suggest a small addition to the $location service.
Before I make any changes to the framework's code I'd like to see what the community thinks.

My one page app resides on a page that's not the root of the site (www.domain.com/onepageapp). In order to avoid including the name of my page in all my route definitions I added the <base href="/onepageapp/" /> tag to the head of the html as it seems to be the accepted solution.
Everything worked wonderfully, but then I decided to add an in-page anchor (<a href="#anchor" />). That's when I realized that the <base> tag also changes the relative path of every link on the page (link was changed to 'domain.com/#anchor' instead of 'domain.com/onepageapp#anchor').

Shouldn't there be a way to modify Angular's base path without having to put up with the extra behavior of the <base> tag?
I suggest adding a way to set the location's base url manually like so:

angular.config(function () {
    $locationProvider.baseHref('/my/nested/base/path');
});

What do you guys think? Is there an obvious implication I haven't considered?

Dave Geddes

unread,
May 27, 2013, 12:55:26 PM5/27/13
to ang...@googlegroups.com
I think Angular needs this as well. Posted an issue on the tracker:
Reply all
Reply to author
Forward
0 new messages