-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirect abstract states #497
Comments
Maybe something like .state('client', {
url: '/client/:clientId',
abstract: true,
redirectTo: 'client.details'
}) |
I tried with $urlRouterProvider
.when('/clients/:clientId', '/clients/:clientId/details') But it doesn't work.. |
Just use $state.go(), or the Wiki has documentation about default child states.
or Wiki Default Child States |
thanks @nateabele I figure it out, that I had a mistyping in the I still have a problem though... given this routing $stateProvider
.state('client', {
url: '/client/:clientId',
abstract: true
})
.state('client.details' {
url: '/details',
templateUrl: '/views/mytemplate.html',
controller: 'ClientDetailsCtrl'
});
$urlRouterProvider
.when('/client/:clientId', '/client/:clientId/details') This is working, when I go to But when I navigate using Uncaught Error: Cannot transition to abstract state 'client.details Is this by design and I shouldn't be calling an abstract state? I thought that the redirection would happened before the state call... |
I'm running into what I think is the same issue. I'm using |
Yes, and yes. If the state is always redirecting anyway, just don't make it abstract. |
If state has child state then only we make it abstract.. As per your use following is the eg. Eg. so if u want to redirect to this state on some action |
$stateProvider
.state('client', {
url: '/client/:clientId',
templateUrl: '/views/parent.html', // must have <div ui-view></div>
controller: 'ClientDetailsCtrl',
abstract: true
})
.state('client.default' {
url: '',
templateUrl: '/views/mytemplate.html'
})
.state('client.details' {
url: '/details',
templateUrl: '/views/mytemplate.html'
}); |
Some directives used $state.go(parentState); and they didn't know anything about states(abstract or not), so I think redirectTo feature should be implemented in ui-router |
+1 for a tested redirectTo feature |
Use DSR from |
The lack of a default on abstract states appears to be a glaring omission given its usefulness and the recurring demand for it. Using "when" to redirect is not a direct solution and feels like a hack. What developers are looking for is to $state.go('target') where 'target' resolves to an optional default, if set, given an abstract target. Otherwise we are messing with URLs rather than states as a work-around. |
There is a default on the abstract state, and there are a couple of options for implementing (per the wiki), and they both work except when you use ui-sref. I.e., if you type the url to the abstract state into the browser, it correctly loads the default child state. But, if you click on a link that goes to the abstract state, it's gets the error. Why would the two things behave differently when it's the same URL? |
@pduey That shouldn't happen. Open a new issue and post a plunkr that demonstrates it. |
I'm having the issue described by @pduey as well. I'll put up a new issue with plunkr. |
As a note here, having the |
I have been using the ui-router in a tree menu that generates from a JSON object. I was having a horrible time with this, this being the ui-sref not working and the FAQs saying that it should work. At the end of it all, I created some code that appended .index onto any parents that I wanted to load in an "overview" child page. I will be posting the entire solution up in a couple days. It's a wreck at the moment otherwise i would upload it now. It's fairly useful for roughing together prototypes that need a fairly complex, multi-level tree structure. |
@zenpuppet That sounds like something worth adding to the wiki FAQ. |
I have just uploaded the code. I am doing a bit of polish on it so its slightly more robust. I am fixing my code so you can define if you want a parent to use just the <div ui-vew></div> as a template or if you actually have a templateUrl. I also want to fix it so that in the parent node you can define a particular child as the default subview. I'm doing that today. If you are interested in seeing the code in its current state let me know. |
@zenpuppet No, that's fine (thanks for asking). Ping when it's polished. |
@zenpuppet have you advanced on this? |
This solution works and it needs more exposure: |
Is there any way to redirect to another state when I try to load an abstract state?
I'd like to redirect to the
client.details
state whenever I navigate to the url that match theclient
statethanks
The text was updated successfully, but these errors were encountered: