AngularJS中的奇怪行为如果在url中传递参数,则重定向

Here is my JS

.when('/showprofile/:UserID', {
                    templateUrl: 'resources/views/layout/showprofile.php',
                    controller: 'ShowOrderController',
                  })

and in the last line i have

app.controller('ShowOrderController', function($scope, $routeParams) {
    $scope.UserID = $routeParams.UserID;
});

Here's the link i am dealing with

localhost/project/#/showprofile/18

Whenever i enter this link, i am getting redirected to

localhost/project/#/showprofile/:UserID

Why it is redirected ? What is the mistake i am doing ?

I think you are passing the parameter in a wrong way. Instead of:

.when('/showprofile/:UserID'

try this:

.when('/showprofile/user=:UserID'

You have to assign the value 'UserID' to be passed to a parameter, say 'user'.

The final url will be like this:

localhost/project/#/showprofile/user=:UserID

i have tried similar example and it worked.

angular.module('myApp', ['ngRoute'])

.config(function($routeProvider){
  $routeProvider.when("/:firstName/:middleName/:lastName",
    {
      templateUrl: "app.html",
      controller: "AppCtrl",
      controllerAs: "app"
    }
  );
})

.controller('AppCtrl', function($routeParams) {
  this.message = $routeParams.firstName + " " + $routeParams.middleName + " " + $routeParams.lastName;
});

compare it with your code if something is wrong.