2016-11-14 10 views
1

私のURLが似ているとリダイレクト:このページでhttp://localhost:3000/family/#/savings/subscribe/123456が他のプロジェクトにangularJs

、私は私が必要を追加しようとしたバックボーン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

答えて

0

角度での問題は、それは、彼の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に:このような何かを試してみてくださいベースを変更する(/私の場合は家族/#/である)私はちょうど私のコントローラで追加されていたので、あなたはプロジェクトから外部のURLに行っているように、それは次のようになります。

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

私は必要はありません。私の '$ routeProvider'内のアップデート

1

他のプロジェクトがあなたのアングルアプリに含まれていない場合は、別のURLにリダイレクトする必要があります。

ちょうど<a href="http://localhost:yourOtherPort"></a>を使用してください。

ng-hrefは、のハッシュの後に、あなたが渡しているURLをの後に追加するためのものです。

+1

リンク内のハッシュタグを削除する場合は、次のリンクをクリックしてください:https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag – trichetriche

2

私はこの質問を理解していませんが、アンギュラルーティングの傍受を避けたい場合は、アンカーターゲット= "_ self"を追加する必要があります。

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

追加するにはここをクリックhttps://docs.angularjs.org/guide/$locationの「HTMLリンクの書き換え」にあります。 – C14L

1

href(または任意の亜種)でリダイレクトする代わりに、コントローラで新しいURLにリダイレクトする関数を使用してみてください。あなたがしたいので、もし

<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 =" path-to-the-other-app "'を使う代わりに、専用のメソッドを持つコントローラを用意し、 'ng-click'でリンクを扱う必要があります。私はあなたに同意しません。 – Maxime

関連する問題