简体   繁体   中英

Redirection issues in angularjs

Hi I am new to angular js..

I have a couple of issues which i am getting while trying to implement a tv-guide website.I have implemented promise in my application.js file.

This is the code for application.js

    .when('/programme/:programmename', {                           //Url rewriting 
                templateUrl:"programme/info.html" ,

                resolve: {
                    programmeid: function (userAPI, $q, $route,$rootScope) {
                        var deferred = $q.defer();

                        var url = $route.current.params.programmename;
                        url = url.replace(/-/g, ' ') ;
                        userAPI.getProgrammeid({ programmename: url }, function (r) {
                            deferred.resolve($rootScope.Programmeid= r.getprogrammeidbyname.programmeidbyname.programmeid);
                            // now promise 
                        });

                        return deferred.promise;
                    }
                }

            })

            .when('/channel/:channelname', {                           //Url rewriting
                templateUrl:"channels/details.html" ,

                resolve: {
                    channelid: function (userAPI, $q, $route,$rootScope) {
                        var deferred = $q.defer();

                        var url = $route.current.params.channelname;

                        url = url.replace(/-/g, ' ') ;
                        userAPI.getChannelid({ channelname: url }, function (r) {
                            console.log("this**********************")
                            console.log(r)
                            deferred.resolve($rootScope.Channelid= r.getsinglechannelidbyname.singlechannelidbyname.channelid);
                            // now  promise is resolved,
                        });

                        return deferred.promise;
                    }
                }

            })
 .otherwise({
            redirectTo:'/home'
        });

I am implementing /#!/programme/programmename.

So I am getting the url in most cases for eg-programme/The-Big-Bang-Theory

The problem I am getting is when there is a slash in the programme name for eg:-Premier League 2013/14 it redirects to the home page or even if there is a dash in the url for eg:- Truth Exposed - Aliens I am getting Truth-Exposed --- Aliens and am getting an error(No url found)or getprogrammeidbyname=null is not defined

Please help me on this one..Thanks in advance.

You can use a * in routes to match like this:

.when('/programme/:programmename*', {

See the api docs for $routeProvider

path can contain named groups starting with a colon and ending with a star (:name*). All characters are eagerly stored in $routeParams under the given name when the route matches.

您可以在传递程序名称之前使用encodeURIComponent()对其进行编码吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM