使用 angularJs 重定向到其他项目
redirect with angularJs to other project
我的 URL 是这样的:http://localhost:3000/family/#/savings/subscribe/123456
在此页面中,我想单击一个按钮将我重定向到另一个使用 backbone JS 制作的项目的其他页面
我尝试使用 href- 和 ng-href http://localhost:3000/admin#exemption
添加所需的 URI:但它总是将我重定向到 http://localhost:3000/family/#/admin#exemption
angular.module('app', ['ng', 'ngRoute', 'ui.bootstrap', 'angularMoment', 'chart.js'])
.config(fac['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/index', {
templateUrl: '/family/index',
controller: 'IndexCtrl'
})
.when('/family/exemption', {
templateUrl: 'exemption-search-view'
})
当我提供所需页面的模板时,我获得了 html 视图,但 URI:http://localhost:3000/family/#/admin#exemption
如果您的其他项目不属于您的 angular 应用程序,您应该重定向到另一个 URL。
只需使用 <a href="http://localhost:yourOtherPort"></a>
.
ng-href 是为了在 URL.
中的散列之后附加 URL 你传递的
我不确定是否理解这个问题,但是如果你想避免angular 路由拦截,你应该在你的锚点中添加 target="_self"。
<a ng-href="{{vm.logoutUrl}}" target="_self">Bye!</a>
不要使用 href(或任何变体)重定向,而是尝试使用控制器中的函数将您重定向到新 url。尝试这样的事情:
// in your controller
angular.module('app', ['ngRoute'])
.controller('redirectCtrl', function($window, $location){
var vm = this;
vm.wizard = {
anotherurl: "http://example.com",
redirect: fnRedirect
}
return vm.wizard;
function fnRedirect(link){
//this way is useful if you try to redirect to an external URL
$window.location = link;
//this way is useful if you try to redirect to another route inside the same angular project
$location.path(link);
}
});
...在您的 html...
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body data-ng-controller="redirectCtrl as rc">
<input type="text" data-ng-model="rc.anotherurl" />
<a href="" data-ng-click="rc.redirect(rc.anotherurl)">Redirect me</a>
</body>
</html>
Angular 中的问题,它会将您重定向到他 URL 中的相同基地,因此如果您想更改基地(在我的情况下是 /family/#/),就像您要从项目中转到外部 URL,所以我刚刚在我的控制器中添加了:
$window.location.href ='http://localhost:3000/admin#exemption' ;
我的“$routeProvider”不需要任何更新
我的 URL 是这样的:http://localhost:3000/family/#/savings/subscribe/123456
在此页面中,我想单击一个按钮将我重定向到另一个使用 backbone JS 制作的项目的其他页面
我尝试使用 href- 和 ng-href http://localhost:3000/admin#exemption
添加所需的 URI:但它总是将我重定向到 http://localhost:3000/family/#/admin#exemption
angular.module('app', ['ng', 'ngRoute', 'ui.bootstrap', 'angularMoment', 'chart.js'])
.config(fac['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/index', {
templateUrl: '/family/index',
controller: 'IndexCtrl'
})
.when('/family/exemption', {
templateUrl: 'exemption-search-view'
})
当我提供所需页面的模板时,我获得了 html 视图,但 URI:http://localhost:3000/family/#/admin#exemption
如果您的其他项目不属于您的 angular 应用程序,您应该重定向到另一个 URL。
只需使用 <a href="http://localhost:yourOtherPort"></a>
.
ng-href 是为了在 URL.
中的散列之后附加 URL 你传递的我不确定是否理解这个问题,但是如果你想避免angular 路由拦截,你应该在你的锚点中添加 target="_self"。
<a ng-href="{{vm.logoutUrl}}" target="_self">Bye!</a>
不要使用 href(或任何变体)重定向,而是尝试使用控制器中的函数将您重定向到新 url。尝试这样的事情:
// in your controller
angular.module('app', ['ngRoute'])
.controller('redirectCtrl', function($window, $location){
var vm = this;
vm.wizard = {
anotherurl: "http://example.com",
redirect: fnRedirect
}
return vm.wizard;
function fnRedirect(link){
//this way is useful if you try to redirect to an external URL
$window.location = link;
//this way is useful if you try to redirect to another route inside the same angular project
$location.path(link);
}
});
...在您的 html...
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body data-ng-controller="redirectCtrl as rc">
<input type="text" data-ng-model="rc.anotherurl" />
<a href="" data-ng-click="rc.redirect(rc.anotherurl)">Redirect me</a>
</body>
</html>
Angular 中的问题,它会将您重定向到他 URL 中的相同基地,因此如果您想更改基地(在我的情况下是 /family/#/),就像您要从项目中转到外部 URL,所以我刚刚在我的控制器中添加了:
$window.location.href ='http://localhost:3000/admin#exemption' ;
我的“$routeProvider”不需要任何更新