2

次の設定を使用する UI-Router(-extras) を使用して AngularJs アプリケーションを開発しています。

  .state('root', {
    url: '/{language:(?:nl|en)}',
    views: {
      'root': {
        templateUrl: 'app/root/root.html',
        controller: 'RootController'
      }
    }
  })
  .state('root.main', {
    views: {
      'main': {
        templateUrl: 'app/main/main.html',
        controller: 'MainController'
      }
    },
    sticky: true
  })
  .state('root.modal', {
    url: '/{locale:(?:nl|fr)}',
    views: {
      'modal': {
        templateUrl: 'app/modal/modal.html',
        controller: 'ModalController'
      }
    }
  })

ルート状態は、URL の言語を定義します。さらに、独自の URL (つまりroot.main.home=> /en/home) を持ついくつかのモーダル状態とメイン状態があります。

ここで、URL のないいくつかのモーダル状態が必要です。州に親の URL を無視させるにはどうすればよいですか?

4

1 に答える 1

5

To answer:

how can a state ignore his parent's URL?

we have

Absolute Routes (^)

If you want to have absolute url matching, then you need to prefix your url string with a special symbol '^'.

$stateProvider
  .state('contacts', {
     url: '/contacts',
     ...
  })
  .state('contacts.list', {
     url: '^/list',
     ...
  });

So the routes would become:

  • 'contacts' state matches "/contacts"
  • 'contacts.list' state matches "/list". The urls were not combined because ^ was used.

Also check this: how to implement custom routes in angular.js?

于 2015-08-31T11:51:18.667 に答える