0

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

1

1 Answer 1

1

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" }

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.