AngularJS显示参数后重定向

问题描述:

这是我的问题

到目前为止,我甚至没有获得url值。但我现在能够获得url paameter但问题是,我的页面重新导向​​一次显示了警报

So far i didn't even get the url value. But now i can able to get the url paameter but the problem is that my page is getting redirected once showing the alert

下面是我的控制器和路线

Here is my controller and route

路线

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

控制器;

app.controller('ShowUserCtrl', function($scope, $routeParams) {
 var b = $routeParams.UserID;
 alert(b);
    $scope.userid = $routeParams.UserID;
});

我的观点:

{{userid}}

问题是我的网址是这样的。

The problem is My Url is like this

http://192.168.1.58/myapp/#/showprofile/18

显示警报后 18

这使得URL像

http://192.168.1.58/myapp/#/showprofile/:UserID

如何停止重定向??

我只是想这是我最后的网址

I just want this as my final url

http://192.168.1.58/myapp/#/showprofile/18

我发现问题是因为我有功能的 .RUN

I found that the problem is because of .run function that i have.

取出后它的作品不错。

After removing it works good.

下面是我的 .RUN 函数

.run(function ($rootScope, $location, Data, $http) {
            $rootScope.$on("$routeChangeStart", function (event, next, current) {
                $http.post('CheckSession', {}).then(function (results)
                {
                    console.log(results.data);
                    var nextUrl = next.$$route.originalPath;
                    if (nextUrl == '/signin' || nextUrl == '/login' || nextUrl == '/verify' || nextUrl == '/registration' || nextUrl == '/forget' || nextUrl == '/invalidtoken' || nextUrl == '/registersuccess')
                    {
                        console.log('outpages');
                    }
                    else
                    {
                        if (results.data == 1)
                        {
                            console.log('loggedin');
                            console.log(nextUrl);
                            console.log('to be redirect');
                            $location.path(nextUrl);
                        }
                        else {
                            console.log('not logged in');
                            $location.path('login');
                        }
                    }


                });
            });
        });