30

I have these states:

.state('quotes', {
  abstract: true,
  url: '/quotes'
})
.state('quotes.new', {
  url: '/new',
  templateUrl: 'views/quote-form.html',
  controller: 'QuoteFormCtrl'
})
.state('quotes.new.customer', {
  url: '?customer',
  templateUrl: 'views/quote-form.html',
  controller: 'QuoteFormCtrl'
})

When I hit the URL /quotes/new?customer=123 the ?customer query string is stripped off, and I am left at the quotes.new state.

What would make most sense to me is just adding a params: ['customer'] to the quotes.new state definition, but that gives me an error complaining that I specify both url and params.

Any examples of what I'm trying to do would be much appreciated.

1 Answer 1

47

You should modify the url string property to include your customer query parameter, like this:

.state('quotes.new', {
  url: '/new?customer',
  templateUrl: 'views/quote-form.html',
  controller: 'QuoteFormCtrl'
});

Multiple parameters can be added by separating them with an &:

.state('mystate', {
  url: '/myState?paramOne&paramTwo
  //...
});

See the docs

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

7 Comments

Thanks. I knew it had to be simpler than I was making it.
how does this work with $state.go? $state.go('quotes.new', {customer: 'dave'}) ?
how does this work with multiple parameters in query string? url: '/new?customer&format'?
So you can't expect a random query param in the url and access it?
|

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.