Skip to content
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

Default child state solution does not work with ui-sref links #2255

Closed
filipesilva opened this issue Sep 20, 2015 · 6 comments
Closed

Default child state solution does not work with ui-sref links #2255

filipesilva opened this issue Sep 20, 2015 · 6 comments

Comments

@filipesilva
Copy link
Contributor

(follow up from #497)

As per the FAQs, to setup a default child state you merely have to set url: "" on the child.

That works well for href links, but nor for ui-sref ones, which has the side effect of also making ui-sref-active not work.

Plunkr: http://plnkr.co/edit/MhJael2qqrGtXe4VHsQO?p=preview

@eddiemonge
Copy link
Contributor

Since you are defining what you want to be the "default" state, you have to transition to that state. Default does not mean redirectTo. Thats a feature thats planned for the future. Using regular 'href' doesn't do the same even though it certainly appears to. It actually transition to the child state directly, as if you have put 'parent.childState' in a ui-sref.

@filipesilva
Copy link
Contributor Author

I think I see the difference between default and redirectTo now.

So the FAQ entry about setting up a default child state can only ever work for href links, correct? An ui-sref link would always target a specific state and thus not work (and neither would ui-sref-active).

@filipesilva
Copy link
Contributor Author

I was re-reading the original thread and as per @nateabele response to @pduey, this difference in behavior should not happen. Am I missing something here?

@timricker
Copy link

@filipesilva did you ever get to the bottom of this or find a workaround?

Its not clear if there is there in fact a gap in functionality to set a default child state with parent abstract state (when using ui-sref), or if this should be working.

@filipesilva
Copy link
Contributor Author

No, I didn't get any further on this topic. At the moment I just use the redirectTo implementation described in #1584 (comment), it's been working well for me in production so far.

@joaovieira
Copy link

I managed to work around by removing the abstract state and have the detail targeting the grandparent state.

Before:

.state('app.resources.products', {
  abstract: true,
  url: '/products',
  template: '<ui-view/>'
})
.state('app.resources.products.list', {
  url: '',
  template: '<div>Products list</div>'
})
.state('app.resources.products.detail', {
  url: '/:productId',
  template: '<div>Product detail</div>'
})
<!-- not working -->
<a ui-sref-active="active" ui-sref='app.resources.products'></a>

After:

.state('app.resources.products', {
  url: '/products',
  template: '<div>Products list</div>'
})
.state('app.resources.products.detail', {
  url: '/:productId',
  views: {
    '@app.resources':{
      template: '<div>Product detail</div>'
    }
  }
})
<a ui-sref-active="active" ui-sref='app.resources.products'></a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants