首页 > 解决方案 > 如何以角度2重定向页面

问题描述

当前页面是http://localhost:4200/#/workrec-list

我想去http://localhost:4200/#/single

如何以角度做到这一点?

我有

this.router.navigate(['/single'], {queryParams: {month: this.data.month}});

但它不起作用。并且有错误

Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: '/single'

标签: angularroutesangular-ui-routerangular2-routingrouter

解决方案


    This code will help you to solve redirection problem of yours i am also attaching jsfiddle[link text](http://jsfiddle.net/5DMjt/25081/)


            <html ng-app="myApp">
            <head>
            </head>
            <body ng-controller="myCtrl">
                <p> <a href="https://docs.woocommerce.com/document/create-a-plugin/"><button>Click me to redirect from template</button></a></p>
                <p ng-click="myFunction()"> <button>Click me to redirect from controller</button></p>
            <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
            <script>
                var app = angular.module('myApp',[]);
                app.controller('myCtrl',function($window,$scope){
                    $scope.myFunction = function(){
                    $window.location.href = 'http://delmarts.com/'; //You should have http here.
                    }
                });
            </script>
            </body>
            </html>

推荐阅读