amcdnl
amcdnl

Reputation: 8648

Base Href and Angular Routing and Views

I'm developing a web application which defines the <base href="phoenix/"> in the header as explained in this article.

The default URL that is mapped is http://localhost/phoenix/ however even when defining the base tag in the header my views and routes are not being redirected correct.

I enabled HTML5 routing:

$locationProvider.html5Mode(true);

and then defined my route like:

app.config(["$routeProvider", function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: '/views/login.html',
        controller: 'LoginCtrl'
    });
}]);

It tries to resolve it as:

 GET http://localhost/views/login.html 404 (Not Found) 

It works correctly if I append the base url to the /phoenix/login paths. Should I have to append that via a variable I set or something or am I missing something and this should work. Also, is this going to work on say IE8 with the header attribute base?

Upvotes: 2

Views: 9550

Answers (1)

amcdnl
amcdnl

Reputation: 8648

Removing the slash from the views

app.config(["$routeProvider", function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: 'views/login.html',
       controller: 'LoginCtrl'
    });
}]);

and making links like:

 <a href="login">Login</a>

but leaving the slash for the route resolved the problem.

Upvotes: 4

Related Questions