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.
What are query string parameters? Query string parameters are extensions of a website's base Uniform Resource Locator (URL) loaded by a web browser or client application. Originally query strings were used to record the content of an HTML form or web form on a given page.
Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.
import ActivatedRoute from '@angular/router'. Inject ActivatedRoute class in constructor. Access queryParams property of ActivatedRoute class which returns an observable of the query parameters that are available in the current URL route.
A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML, choosing the appearance of a page, or jumping to positions in multimedia content.
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¶mTwo //... });
See the docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With