Reputation: 291
I want to define some state with optional url in angular ui-router
how can I do this?
for example
state('test',{
url:'/list/:id/color?/:color?'
}
in this example the color and :color is optional and state should work whit these urls:
site.com/list/1
site.com/list/color/red
Upvotes: 0
Views: 37
Reputation: 8171
There was an update to the library a few years ago which allowed this functionality:
$stateProvider.state("foo", {
url: "/foo/{foo}",
params: {
foo: { value: "bar" }
}
});
Adding a default value to foo means that the route above will match
/foo
,/foo/
, and/foo/baz
. Additionally, when matching/foo
or/foo/
,$stateParams
will still be populated with{ foo: "bar" }
Upvotes: 1