问题
What is the angular way for maintaining a URL scheme in the following context:
- the app contains a sidebar where the user can select a number of datasets, and modify the selection later on.
- there's a dashboard canvas onto which a user can dynamically add a number of windows that contain different types of figures. These figures are plotted based on certain variables.
The URL scheme I'm thinking would allow me to keep track of the selected datasets, current active windows, their parameters and their respective order. For example, a valid url could be
/ds?set=dataset1,dataset2,dataset3/type1?var=alb&f=0.05-0.15/type3?var=alb,crea/type1?var=alb,crea,ch2&f=0.10-0.20/
which would mean the three named datasets are currently selected, and further, three windows are active in the defined order with the defined query parameters.
What state/view structure would allow the described schema? The problem is that I have not seen any examples of such a situation, the ui-router examples are all simple hierarchical cases where user navigates on a given path.
回答1:
I'm not entirely clear on your desired url scheme, but this could be accomplished with query parameters in the route. The limitation with this is they have to be declared to the state when the state is defined ex:
.state('dashboard', {
url: '/dashboard?ds&type&foo&bar'
})
This would make $stateParams.ds
, $stateParams.type
, $stateParams.foo
etc available. The issue of some arbitrary set of parameters being required (i.e. you don't know them all ahead of time) can be resolved by serializing the params in some way to the known named parameters.
For example, I use query params for doing some redirects between states where the state is captured in the query params ?redirect=profile.details&profileId=987234
and I can deserialize this to something I pass straight to $state.go()
. In this case I have a limited set of ids that could be passed so I have them declared int the state definition. To get around this you could do something like ?redirect=state.name&attrs={someId:3,otherValue:'abc',andAntoher:324}
. (the query parameters should be urlencoded) and this way the state's url
could be declared like this: /dashboard?redrect&attrs
来源:https://stackoverflow.com/questions/24224543/non-hierarchical-url-scheme-for-a-dashboard-application