#[Url]
Sync component properties with the URL query string.
Basic Usage
Properties marked with #[Url] are automatically reflected in the URL.
use LiVue\Attributes\Url;
class UserList extends Component
{
#[Url]
public string $search = '';
#[Url]
public string $sort = 'name';
#[Url]
public int $page = 1;
}
When the user searches, the URL becomes: /users?search=john&sort=name&page=1
Custom Query Parameter Name
Use a different name in the URL than the property name.
#[Url(as: 'q')]
public string $search = '';
// URL: /users?q=john
History Mode
Control whether URL changes create new browser history entries.
// Default: replaces current history entry
#[Url]
public string $filter = '';
// Push new history entry (enables back button)
#[Url(history: true)]
public int $page = 1;
Hiding Default Values
Keep the URL clean by excluding parameters when they match the default value.
#[Url(except: '')]
public string $search = '';
// Empty search = no ?search= in URL
// Non-empty search = ?search=value
Common Use Cases
Search & Filters
Users can bookmark or share filtered views.
Pagination
Navigate pages with the browser's back/forward buttons.
Tab State
Deep link to specific tabs within a component.