I need to construct a state url based on an object. Basically I want this state:
{
id: 1,
f: {
"5": [
"1",
"7"
],
"7": [
"3",
"6"
]
}
}
To be transformed into this url:
http://localhost/resource/1?f[5][]=1&f[5][]=7&f[7][]=3&f[7][]=6
How do I specify such a url pattern with the ui-router config and how do I transition to that state?
Edit: I wasn't really clear on how or why I wanted this.
The main idea is to create a filter for some data on a page. I'd like the users to be able to bookmark the page with their filters applied.
The specific format of the url is nothing I invented, it's the standard way to provide arrays in query parameters for PHP. PHP parses the query with parse_str()
, like this:
php > parse_str('f[5][]=1&f[5][]=7&f[7][]=3&f[7][]=6', $arr);
php > var_dump($arr);
array(1) {
["f"]=>
array(2) {
[5]=>
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "7"
}
[7]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "6"
}
}
}
What I want to do is to call $state.go()
with my filter parameters (something like the state object above) and make ui-router change the url and state to those parameters on this specific url format.
I'm open to suggestions if there is a better way to do this.