1

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?

Alexander Presber
  • 6,429
  • 2
  • 37
  • 66

1 Answers1

1

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

Roland Studer
  • 4,315
  • 3
  • 27
  • 43