Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI-Router Not Going to Correct State from URL

I have a bit of a complicated set up with lots of nested tabs / views. Here are the relevant parts of my $stateProvider

$stateProvider
    .state('tab', {
        abstract: true,
        url: '',
        templateUrl: 'tabs.html'
    })
    .state('tab.event', {
        url: '/event',
        views: {
            'event': {
                abstract: true,
                templateUrl: 'event-tabs.html'
            }
        }
    })
    .state('tab.event.list', {
        url: '/list',
        views: {
            'list': {
                templateUrl: 'event-list.html'
            }
        }
    })
    .state('tab.event.detail', {
        cache: false,
        url: '/:id',
        views: {
            'detail': {
                abstract: true,
                templateUrl: 'event-detail-tabs.html'
            }
        }
    })
    .state('tab.event.detail.info', {
        cache: false,
        url: '/info',
        views: {
            'info': {
                templateUrl: 'event-detail-info.html'
            }
        }
    })
    .state('tab.event.detail.map', {
        cache: false,
        url: '/map',
        views: {
            'map': {
                templateUrl: 'event-detail-map.html'
            }
        }
    });
  • Using ui-sref="tab.event.detail({id: event.id})" I can link to the tab.event.detail.info state and the URL changes to /event/:id/info, good.
  • If I enter the URL /event/:id it will redirect to /event/:id/info, good.
  • BUT if I enter the URL /event/:id/info the state will change to tab.event.list and URL to /event/list, not good.

I'd like to be able to share links to /event/:id/info and /event/:id/map but they keep redirecting to /event/list
Tried lots of things but can't get it to work, please help!

Edit: Made a Plunker example but I can't replicate the problem because I can't directly manipulate the URL of the app. https://plnkr.co/edit/7iZAH26SwAILqBfkdXJS?p=preview

like image 548
barro32 Avatar asked May 25 '16 14:05

barro32


People also ask

What is ui sref in AngularJS?

State-To-State Navigation of ui-sref in Angular The ui-sref directive is the first option to navigate from one state to another. The href property of the HTML anchor element is likely acquainted with you; likewise, the ui-sref directive refers to a state reference.

What is ui view in AngularJS?

The ui-view directive tells angularJS where to inject the templates your states refer to. When a state is activated, its templates are automatically inserted into the ui-view of its parent state's template. If it's a top-level state—which 'business' is because it has no parent state–then its parent template is index.

What is ui in router?

UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).


1 Answers

Your "tab.event.detail" state is an abstract state that means the state it self can not be activated by it self so it will automatically load the child state in this case "tab.event.detail.info" state.

Remember: only one state at a time can be activated.

Refer to the documentation https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views

like image 138
ShegaMike Avatar answered Sep 30 '22 00:09

ShegaMike