StimulusReflex: How to change the URL on reflex

212 Views Asked by At

We are using StimulusReflex and want to change the URL on specific reflexes (e.g. using the Browser pushState API, e.g. via cable_ready ??).

Is this a common thing with StimulusReflex? Are there good examples somewhere?

1

There are 1 best solutions below

0
On

Yes, you can update the URL using cable ready:

class SomeReflexClass
  def your_reflex
    cable_ready.push_state(url: new_url, state: {turbo: true})
  end
end

With turbo links setting the state to turbo: true was necessary for turbo links to handle the back button correctly, not sure if it still necessary with Turbo Drive