0

I have a couple of parameters that are fundamental and often present in my application.

Simplified exemple of url in the router definition:

url:'/settings/:id'
url:'/profile/:id'
url:'/account/:id'

Do I need to pass this :id parameter on every state.go() or ui-sref?

Example:

ui-sref="settings({id:vm.id})"
ui-sref="profile({id:vm.id})"
ui-sref="account({id:vm.id})"

I would be much simpler if there were a way to copy the named url parameters and specify a specific parameter if I would like to replace it or omit it.

Example:

ui-sref="account"

And if and only if I would like to overwrite it:

ui-sref="account({id:vm.anotherId})"

According to the API inherit is the default behaviour: "inherit Boolean (default true), If true will inherit url parameters from current url." https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options

And this applys to ui-sref also according to: "There is no functional difference between ui-sref and $state.go. See the doc" Difference between ui-sref and $state.go in AngularJS UI-Router

This seems trivial, or I misunderstand something :-( I have tried playing around with nested states, but the real application has not the nested states carasteristics.

2
  • 1
    I don't really see the point. Why would you want to go from the account 1234 to the profile 1234? account and profile are two completely separate resources, aren't they? If they're two separate parts of the same resource, you'd better use URLs like /foos/:id/profile, /foos/:id/account, and you would then be able to use a parent foo state, and use sibling paths: ^.profile, ^.account. Commented Dec 29, 2016 at 23:03
  • Sounds fair! Ill try it. Commented Dec 29, 2016 at 23:09

1 Answer 1

2

I think you need to invert the order of your url, changing it to something like this:

url: user/:id/settings
url: user/:id/profile
url: user/:id/account

It makes more sense this way anyways, you're not looking up the id of a setting, you're looking up the settings of a user/application/website/etc with an id of :id. You can just make the parent state user be abstract and have one of the child states be the default state that navigates to user/:id. That way, the id will be inherited, but you can transition simply by saying ui-sref="^.account" (a relative state transition).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.