Skip to content

Add Config class for Ziggy configuration management (dynamic configuration)#857

Closed
thaqebon wants to merge 2 commits intotighten:2.xfrom
thaqebon:2.x
Closed

Add Config class for Ziggy configuration management (dynamic configuration)#857
thaqebon wants to merge 2 commits intotighten:2.xfrom
thaqebon:2.x

Conversation

@thaqebon
Copy link

Summary

  • Introduced a Config class to manage Ziggy configuration.
  • Added static set(), get() and absolute() methods for default configuration.
  • Updated Route and Router classes to use the new Config class.
  • Added tests to ensure the config behavior is consistent and reliable.

Purpose

The main goal of this PR is to allow dynamic configuration of Ziggy at runtime by setting a config getter:

 // Inertia example
ZiggyConfig.set(() => usePage().props.ziggy);
 // DOM-based config
ZiggyConfig.set(() => JSON.parse(document.getElementById('ziggy-routes-json').textContent));

// Set default absolute flag
ZiggyConfig.absolute(false)

This makes Ziggy more flexible by allowing dynamic configuration instead of relying on a static one.

thaqebon added 2 commits July 31, 2025 03:32
- Added static methods to Config for setting and getting default configurations.
- Updated Route and Router classes to utilize the new Config.
- Added tests to validate new Config class.
@bakerkretzmar bakerkretzmar self-assigned this Aug 5, 2025
@bakerkretzmar
Copy link
Collaborator

Thanks a lot for the PR, and for your patience! This is really interesting but I think I'm going to pass for now. It's a lot of new code to introduce and I'm not sure that this pattern is super common or necessarily something we want to push people towards.

I can see how it could be helpful to eventually have something a bit more polished than Ziggy.location = '...' in Ziggy to handle updating configuration over time, especially for Inertia. If we do go down that road though I think I would want to lean towards something that updates it when it changes, something like route().configure({ ... }) to pass in new options, as opposed to fetching it dynamically on every route() call. Not sure though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants