Coo Coo - 6 months ago 23
AngularJS Question

$state.href with absolute: true doesn't return the right url

I'm using Angular and UI router. I'm trying to get a link shown on the page that the user can copy and share. This thread has shown me that

is the function I'm looking for, however it isn't generating the correct link.

An important detail here is that the root of my application is not the root of the domain. In this case, the domain is
, but the root of the angular app is in

Here's the command I'm using inside my controller.

$scope.url = $state.href('survey', { survey: "asd" }, {absolute: true});

In my app.js, the following route is declared:

.state('survey', {
url: "/:survey/survey?ao",
templateUrl: "views/survey/survey.html",
controller: "surveyController",
data: {
requireLogin: false,
requireAdmin: false

This should return
, instead it returns

(The remarkable thing is that
ui-sref="survey({survey: "asd"})
does translate to the correct link.)

Is there a way I can fix this so I get the full url?


Adding a base tag to my app page solved this issue for me. It defines the base URL for the page with the router references. For legacy support reasons, I'm on version 0.2.15 of Angular UI Router. I don't know if this is still necessary for more current versions.

<base href="http://localhost/dev/app/" />