How about:
app.controller('ProfileCtrl',
function ($scope, $routeParams, User,$location) {
if(!$routeParams.username){
$location.path('/somewhereElse');
}
$scope.user = User.findUsername($routeParams.username);
If you mean if you want to check if the username is a valid one, the only way to do so is through some check, ideally server side with $http
. I would suggest making a service to check the server for valid usernames.