Woohoo!!! Tip #100. I cannot believe we made it this far. If you have a tip, please share and maybe we can get to 200.
I love using query parameters because I can have the user customize a certain route and have all the customization be part of the URL which makes it easier to share and bookmark.
For an example the url https://www.hirejs.com/app/jobs?isContract=true&isRemote=true has 2 query parameters that filter jobs where isContract and isRemote are true.
The code is pretty straightforward, in my controller, I simply added:
1 2 3 4 5 |
queryParams: ['isRemote','isFullTime','isPartTime','isContract'], isRemote: false, isFullTime: false, isPartTime: false, isContract: false, |
That’s pretty much it, then you can bind these properties to inputs and they will change the url as their values are changed. In this case they are bound to a toggle (checkbox) and every time the user toggles it, it changes the URL.
Here is a demo GIF, watch how the URL changes as I click around: