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'
}
}
});
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. /event/:id
it will redirect to /event/:id/info
, good. /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
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.
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.
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With