Angular UI-Router problem

797 views
Skip to first unread message

Finn Poitier

unread,
May 15, 2013, 11:35:43 AM5/15/13
to ang...@googlegroups.com
When having two states defined such as these:

     var rendermycategory = {
          name: 'rendermycategory',
          url: '/:lang/:category',
          views: {
            '': {
              templateUrl: 'index'
            },
            'subtemplate': {
              templateUrl: 'partials/mainCategory',
              controller: UiRouterPageCtrl
            }
          }
        };

     var listPages = {
          name: 'listPages',
          url: '/forms/:modelname',
          views: {
            '': {
              templateUrl: 'index'
            },
            'subtemplate': {
              templateUrl: 'partials/listPages',
              controller: GetPageListCtrl
            }
          }
        };

I would think, that when entering URLs manually:

http://www.mydomain.com/de/mycategory -> would use the state "rendermycategory" (and it does)

but

http://www.mydomain.com/forms/something -> should use the state "listPages", still this URL uses the "rendermycategory" state :(

Is this a "bug"? Or intentional for some reason? Or did I get some concept wrong? (I´m really not sure)

With the "old fashioned" $route provider the differentiation between both of these works as expected.

Ryan Zec

unread,
May 15, 2013, 11:58:42 AM5/15/13
to ang...@googlegroups.com
My guess is if you switch the order of how those states are inserted, it should work (though this is a total guess.

My guess is it is using the first state for the second url because it does match, it just thinks that :lang is forms and :category is something (though not sure why the standard $route works if you are entering them in the same order).



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Finn Poitier

unread,
May 15, 2013, 2:25:03 PM5/15/13
to ang...@googlegroups.com
Yes Ryan, I guessed the same and I´m pretty sure the standard $route provider has something like "priority rules", defining that /hardcoded URL parts have priority before the /:variable ones.

But as far as I´m not missing some point, I think such priority rule wold be very important for UI-router, so some fix or further clarification on that point would be cool :)

Finn Poitier

unread,
May 16, 2013, 7:34:48 AM5/16/13
to ang...@googlegroups.com
Solution...

I stumbled upon this discussion: https://github.com/angular-ui/ui-router/issues/88
and got aware that configuring $urlRouterProvider seems to be a good idea, which I did with the following code:

    $urlRouterProvider
      .when('/forms/:modelname', ['$location', '$state', function ($location, $state) {
        var mylocation = $location.path();
        var mymodelname = mylocation.split("/");
        $state.transitionTo('listPages', {modelname : mymodelname[2]});
      }])

Anyone let me know, if there´s a more suggested or better way to accomplish the issue ;)
Reply all
Reply to author
Forward
0 new messages