Query String

It can be useful at times to update the browser's query string when your Wire's state changes.

Example

Let's say you are building a Wire to search articles, and want the query string to reflect the current search value like so:

https://yourapp.com/search-articles?search=some+string

This way, when a user hits the back button or bookmarks the page, you can get the initial state out of the query string rather than resetting the Wire every time.

You can add a queryString variable to your Wires and CBWIRE will update the query string every time the property value changes and also update the property when the query string changes.

component extends="cbwire.models.Component" {

    data = {
        "search": ""
    };
    
    queryString = [ "search" ];
}
<div>
    <input wire:model="search" type="search" placeholder="Search articles...">
</div>

Last updated