I want to start using Angular's ui-router instead of ngRoute. Originally, my app config looked like
myApp.config(["$routeProvider",
function($routeProvider) {
$routeProvider
.when("/search", {
templateUrl: "partials/customerSearch.html"
})
.when("/home", {
templateUrl: "partials/home.html"
})
.when("/login", {
templateUrl: "partials/login.html",
controller: "LoginCtrl"
})
.otherwise({
redirectTo: "/home"
})
;
}
]);
I swapped out the libraries, and changed the config. I understand I could still use $routeProvider
, but that seems like a legacy workaround.
myApp.config(["$urlRouterProvider", "$stateProvider",
function($urlRouterProvider, $stateProvider) {
$urlRouterProvider
.when("/search", "partials/customerSearch.html")
.when("/home", "partials/home.html")
.when("/login", "partials/login.html")
.otherwise("/home")
;
$stateProvider
.state({
name: "customer",
url: "/customer/:username",
templateUrl: "partials/customer.html"
})
.state({
parent: "customer",
name: "details",
url: "/details",
templateUrl: "partials/customerDetails.html"
})
;
}
]);
This gives me errors that seem to indicate $digest
is stuck in a loop. I suspect the .otherwise("/home")
rule. Am I specifying the handler
s correctly, as if they were template URLs?
If I comment-out the .when()
s, nothing works except "/customer/:username"
. Do I have to have a state defined for every route? If so, what is the point of having both $urlRouterProvider
and $stateProvider
? Asked differently, what is each supposed to do?
controller
property, but the samples all look like mock controllers (anonymous functions). I tried using the name of one of my controllers, both quoted and not, but that didn't seem to work. Additionally, the app still doesn't seem to be routing. – Morton$urlRouterProvider
, or whether I need a state defined for each former route (also asked in your answer). – Morton