2016-11-14 99 views
1

我的网址是这样的:http://localhost:3000/family/#/savings/subscribe/123456与angularJs重定向到其他项目

在此页面

,我想点击一个按钮,我重定向到与骨干由JS 另一个项目的其他页面我试图添加所需的URI与href-和NG-HREF http://localhost:3000/admin#exemption:但它总是重定向我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

回答

0

在角的问题,将您重定向到URL他相同的基础,所以,如果你想换基(这是/家庭/#/在我的情况),这就像你从这样我已经在我的控制器刚刚添加的项目将外部URL:

$window.location.href ='http://localhost:3000/admin#exemption' ; 

我不需要我的'$ routeProvider'

0123中的任何更新
1

如果你的其他项目不是你的角度应用程序的一部分,你应该重定向到另一个URL。

只需使用<a href="http://localhost:yourOtherPort"></a>

ng-href是在这里追加URL中散列后的

+1

如果你想在链接中删除你的hashtag,你可以按照这个链接:https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag – trichetriche

2

我不确定要理解这个问题,但是如果你想要避免角度路由拦截,你应该添加你的锚点target =“_ self”。

<a ng-href="{{vm.logoutUrl}}" target="_self">Bye!</a> 
+0

要添加,这里是在“HTML链接重写”下的文档中:https://docs.angularjs.org/guide/$location。 – C14L

1

而不是重定向与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> 
+0

为什么要重新创建'href'的动作?你不需要使用'href =“路径到其他应用程序'',你需要一个具有专用方法的控制器,并使用'ng-click'来处理链接?!我不同意你的看法。 – Maxime

相关问题