rj93
rj93

Reputation: 573

Why doesnt my $routeProvider work?

I am having trouble getting my $routeProvider to work correctly.

I have the following code:

"use strict";

(function() {
    angular.module("websiteApp", ["ngRoute"])

        .config(["$routeProvider", function($routeProvider){
            $routeProvider
                .when("/example", {
                    templateUrl: "partials/example.html",
                    controller: "ExampleController"
                })
                .otherwise({
                    redirectTo: "/"
                });
        }]);
})();

but when I navigate to localhost/example I get 404 Not Found. Where am I going wrong?

Upvotes: 0

Views: 37

Answers (1)

charlietfl
charlietfl

Reputation: 171698

Quite simply you are using the wrong url. Unless you set $locationProvider.html5Mode(true); all the angular paths will be hash based and include # in them

Try

http://localhost#/example

So you also need to include the hash in any href you use also

<a href="#/example">

Note that html5Mode also requires server configuration if you decide to implement it

Upvotes: 1

Related Questions