2016-08-30 12 views
1

私たちのアプリケーションでは、ここで特定の要件に問題があります。角度ui-routerカスタマイズの問題

私たちは既存のRailsアプリケーションの中に角度のあるアプリケーションを設定しています。

私たちのコードベースの完全なリファクタリングは現在のところ明らかにされていません。私たちはAngularの追加導入を可能にするために、両方のハードカスタマイズとハッキングを扱っています。

私たちが今必要とするのは、ui-routerに、ng-sref属性を持つリンクだけにバインドするように指示する方法です。アプリケーション内のすべての通常のhrefリンクを気にする必要はありません。

この動作を実現する方法はありますか?以下は

私の現在のコードです:この方法で


angular.module('app').config(function($stateProvider, $urlRouterProvider, $locationProvider) { 
    $stateProvider.state('test', { 
        url: "/1/test", 
        template: 'test' 
       }); 

      $locationProvider.html5Mode({ 
       enabled: true, 
       requireBase: false, 
       rewriteLinks: false 
      }) 
     } 
    ) 

、すべてのリンク、それのための任意の経路設定のないものも含めたもの、およびUI-SREF属性なしで、角度ルーティングサービスによって監視されており、以前のように動作しなくなった。私は角ルーティングのセットアップ(これはひどい考えです)への私たちの巨大なアプリのすべてのルートを追加したくないこれらのリンクのほとんどは角度のないページにあるためです。私は角度ルーティングサービスがこのリンク、または定義されていないこれらの場所を無視したいだけです。おそらく$ locationサービスの設定は、それらの人たちが以前の動作(ajax要求、定期的要求、またはTurbolinks要求)と一緒に落ち着かせるようにします。私はこれが本当に些細なことであると確信しています。

これらのリンクをクリックすると、ウィンドウの場所は変更されますが、何も起こりません。ブラウザー要求はトリガーされません。

ありがとうございます。

+1

ui-routerにhrefに一致するURLがある場合は、そこに行きます。一致するURLがない場合は、設定されているものと一致します。 –

+0

ありがとう!しかし、これは私のために働いていません。たぶん私はhtml5modeを使用しているからかもしれません。私は質問の中に私の現在のコードを追加しました。 –

答えて

0
################################################################################### 
# My suggestion is use the ui-router to route to specific pages as shown 
# in the example below. 

# <a ui-sref="/login"> 
# <a ui-sref="/logout"> 
# <a ui-sref="/signup"> 
# <a ui-sref="/profile"> 

# 'ui-sref' will take you to the specific pages. 

# You can also use '$state.go' to take you to specific pages as shown below. 

# $state.go('authentication.login'); 
# $state.go('authentication.logout'); 
# $state.go('authentication.signup'); 
# $state.go('authentication.profile'); 

################################################################################### 

(function() { 
    'use strict'; 

    angular 
     .module('app.foo.authentication') 
     .config(moduleConfig); 

    /* @ngInject */ 
    function moduleConfig($translatePartialLoaderProvider, $stateProvider) { 
     $translatePartialLoaderProvider.addPart('app/foo/authentication'); 

     $stateProvider 
     .state('authentication.login', { 
      url: '/login', 
      templateUrl: 'app/foo/authentication/login/login.tmpl.html', 
      controller: 'LoginController', 
      controllerAs: 'vm' 
     }) 
     .state('authentication.logout', { 
      url: '/logout', 
      templateUrl: 'app/foo/authentication/logout/logout.tmpl.html', 
      controller: 'LogoutController', 
      controllerAs: 'vm' 
     }) 
     .state('authentication.signup', { 
      url: '/signup', 
      templateUrl: 'app/foo/authentication/signup/signup.tmpl.html', 
      controller: 'SignupController', 
      controllerAs: 'vm' 
     }) 
     .state('authentication.profile', { 
      url: '/profile', 
      templateUrl: 'app/foo/authentication/profile/profile.tmpl.html', 
      controller: 'ProfileController', 
      controllerAs: 'vm' 
     }); 
    } 
})(); 
+0

私の問題は、html5オプションを有効にしている可能性があります。この単純な基本的なアプローチは私のためには機能しません。私は上記の私の現在のコードを追加しました。 –

+0

ありがとうございます。しかし、これは私のためには機能しません。私は私の質問にいくつかの説明を追加しました。 –